|
|
Database Not Storing Data? | ||
Discussion by nightfox with 8 Replies.
Last Update: January 13, 2006, 11:37 pm | |||
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:
QUOTE
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
Tue Jan 3, 2006 Reply New Discussion
CODE
<?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.";
?>
Wed Jan 4, 2006 Reply New Discussion
Ok, the table is in my database and is setup. What I really need, is code that can grab information out of the database and display it where I need it as I have a code that can insert information into it.
[N]F
Fri Jan 6, 2006 Reply New Discussion
Fri Jan 6, 2006 Reply New Discussion
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:
CODE
<?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
Sat Jan 7, 2006 Reply New Discussion
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
Mon Jan 9, 2006 Reply New Discussion
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.
Mon Jan 9, 2006 Reply New Discussion
QUOTE (Houdini)
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.I'm not using any software, it is all custom coding by me!
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:
CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta 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://www.coconutproject.com/page.html?id=#</p>
<form 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!!!
[N]F
Tue Jan 10, 2006 Reply New Discussion
He said to use a MySQL "update" instead of "INSERT"? Would that be correct for if I made a page editor?
[N]F
Fri Jan 13, 2006 Reply New Discussion
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.
Wed Jan 18, 2006 Reply New Discussion
New MySQL Server & Blank Fields Problem With Jsp empty fields and data trancation error (0)
|
(19) What Are The Alternatives To MySQL
|
Index




