Jump to content
xisto Community
Sign in to follow this  
nightfox1405241487

Database Not Storing Data?

Recommended Posts

This is puzzling me... :D
I have a database for a global template system I'm coding... I get all the kinks worked out of the PHP portion of it, make a test page, and this is what I'm greeted with:



That's what I get in Firefox when I access the page. Actually, it doesn't matter what ID I give it, that is all that appears.
I'm trying something new but I'd like a PHP script to setup a table in an existing database.

ID -> This should be set to auto-inc so first ID is 1, 2, 3, you get the idea
title -> This is a simple place to store the page title
content -> this is where the content is to be stored. MUST be able to have HTML/JavaScript code since this is what is displayed on the page.

I think my submit page works perfectly. I'll just modify it for the new table.

THANKS!!!

[N]F

Share this post


Link to post
Share on other sites

I noticed that ou are a hosted member so I wrote a little script that you can use then you can go further after success with this and when I know just what it is you are wanting to do. I used a field with TEXT data attribute which allows up to 65000 characters so here is a script that you can copy and past into the root where your index.php or index.html is and run from your home page and create a test table (Inamed this one test1, you could change it to something else but be carefule not to use the name of an existing table or the script will fail.)

<?php$host = "localhost"; //most host are localhost but could be mysql (rare))$user = "root";      // this is a default with no password assigned when first installing put your username in here$pass = "";           // Default also, enter your password here for the database$db   = "databasename"; // This is probably your username_(DataBaseName)$table = "test1";       //lets make a test table you can view this with phpMyAdmin in cPanel after you run this simple script$connect = mysql_connect($host, $user, $pass)     or die("Could not connect to server...check you username and password");$db = mysql_select_db($db, $connect)     or die("Could not connect to Database...check you username and password");echo "Connecting to Database...<br />";$sql = mysql_query("CREATE TABLE $table(id INT(4) NOT NULL AUTO_INCREMENT,title VARCHAR(50),content TEXT,PRIMARY KEY (id))")     or die("Could not create table");echo "Success your new database table <b>$table</b> has been created!<br />!"."You should now eliminate this file from your server for security purposes."; ?>
OK Copy that code and call it table.php or anything you want.php then run it from your home page. Then using phpMyAdmin in the cPanel look at your database and you will see a new table called test1 (unless you changed that part). Remove the file that you just uploaded and used and post back to learn how to use your database.

Share this post


Link to post
Share on other sites

I got it working!!!! I am really really happy now! :D :D

Ok, the thing I need you to check is the script I use to insert data. When I inserted content manually into ID "1" through phpMyAdmin, manually specifying details, it worked.

Here is the script that submits data into the database but doesn't:

<?php#GLOBAL DATABASE CONNECTION SETTINGS$dbname = "DATABASE";//This is the name of your database$dbpass = "PASSWORD";//This is the password to your database$dbuser = "USER";//This is the username for your database$host = "localhost";//Unless your host says otherwise, this is most likely localhost#NO NEED TO EDIT PAST THIS LINE...$db = mysql_connect($host, $dbuser, $dbpass);mysql_select_db($dbname);#END... DATABASE SETTINGS BELOW!$sql = "INSERT INTO `page` ( `id`, 'title`, `content` ) VALUES ( '', '" . $_POST ['title'] . "', '" . $_POST ['content'] . "' );";mysql_query($sql);echo "Page added!";?>

Also, I need a way to edit pages directly from my admin control center but I'm not sure how to do this.

[N]F

Share this post


Link to post
Share on other sites

Can anyone make me a code that will insert data into the database? Apparently my scripts run perfectly, but do not dump the data into the database! Also, how do I call up data from the database into a form to modify it and save it back to the database?[N]F

Share this post


Link to post
Share on other sites

You code is showing a form that gets the data namely id a title and then the content. Is you id auto incremented in your table? Could you show the code for the HTML form because that is where the query is looking for the data, and if it doesn't see those named field on the form it is just putting null or a space into those fields.It would help to see the code for the form. Also Since I don't know what software you are using it is hard to know what your Admin Control Panel does.

Share this post


Link to post
Share on other sites

It would help to see the code for the form. Also Since I don't know what software you are using it is hard to know what your Admin Control Panel does.

1064335248[/snapback]

I'm not using any software, it is all custom coding by me! :D My admin control panel is just a bunch of loose ended pages shoved into a password protected directory on my site. But if anyone even did break in, the most they could do is *attempt* to add pages to the system which doesn't work.

 

There's a problem with the code I posted for the form (form code later on). I tested it again. I made a test page which should have been given the ID of 11. Nope. All I get is my invalid ID message.

 

Here's the code to the form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://forums.xisto.com/no_longer_exists/ http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title></head><body><p><strong>The Coconut Project :: Admin :: Add a Page </strong></p><p>Note: Pages must still be manually linked!</p><p>This script is for making a REGULAR (non-review, non other content) page. The URL for this page will be:<br>  http://http://www.hugedomains.com/domain_profile.cfm?d=coconutproject&e=com name="form1" method="post" action="make_page.php">  <p>Page ID: (MUST be UNIQUE!)     <input name="id" type="text" id="id" value="AUTO-INC ONLY! (1,2,3,etc.)" disabled="true"></p>  <p>Page Title:     <input name="title" type="text" id="title"></p>  <p>Page content (right under "print friendly" button):<br>    <textarea name="content" cols="100" rows="20" id="content"></textarea>    <input name="type" type="hidden" id="type" value="regpage">  </p>  <p>    <input type="submit" name="Submit" value="Add New Page">    <input name="Reset" type="reset" id="Reset" value="Cancel">  </p></form><p> </p></body></html>
What I need is this to send data to the page which contains the code I posted above which adds it to the database. Problem is, the script that adds it to the database isn't adding it to the database for some reason. I don't know why... everything *looks* correct. ;)

 

It's becoming a pain because I don't want to have to login to cPanel then go to phpMyAdmin and manually enter content that way... I'd rather just go to my site, /staff/, login, click a link that takes me to the form page, insert data, and then submit and link.

 

THANKS!!! :D

 

[N]F

Share this post


Link to post
Share on other sites

Lol I typed out an entire example, but then accidently hit a button and it erased the whole thing. I'll just redirect you to a link this time, next time i'll use notepad or something then paste it.

http://www.tizag.com/sqlTutorial/sqlupdate.php

Yes you can use Update to alter current records in your database. That link should clear up how to use the UPDATE clause.

As far as creating a from to do alter a record you'll need these pages/scripts:

1.) Script to select all records from database to be used in #2
2.) Form with select list (or text your choice, but select is usually better) to display all the records from your table. The select options usually have the primary key assigned to their 'VALUE' attribute and the name is usually being displayed.
3.) Script to select all fields you want modified by using the selected value in #2 (should be the primary key) so that it can be used in #4
4.) Form to display current values into fields to be edited (remember not to let admin/user edit primary keys or other fields that shouldn't be altered unless needed)
5.) On submiting #4 a script to update the entries as the admin/user wants

That's the basic way, in my opinion of doing it. It can be done within 1 form page and 1 script page ( or one page entirely) depends on how you like to code. Much simplier to have 2 form pages and place the scripts at the beginning of the form, then on the last form have a script to update, then redirect with a php HEADER.

If you want I could code up a simple example and post it on here, hope this helps, and I hope I understood what you wanted.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.