Albatross
2-21-06, 06:57 PM
I'm having problems getting MySQL INSERT to work. Here's the code block of PHP that does the inserting:
mysql_pconnect("mysql09.powweb.com", "foo", "foo") or die("Can't connect to MySQL Server");
mysql_select_db("news_database") or die("Can't find the MySQL database");
$insertquery = "INSERT INTO news_entries (entrydate, post) VALUES ($completedate, $completetext)";
$result = mysql_query($insertquery) or die("Couldn't add new post.");
$error = mysql_error();
print "$error";
mysql_close();
The table news_entries consists of three fields: entrydate (a date field), post (a text field), and id (an int). id is an auto-increment field and the primary key to guarantee uniqueness. In the example above, I don't try to set a value for id, but just let the auto-increment set it.
The connect and select_db goes fine, but when I try to run the query with mysql_query, I get my die message. mysql_error() returns nothing. Am I just making a syntax mistake here? The only thing I can think of is maybe the date field. I'm trying to insert a string into it (in the form (yyyy-mm-dd) and I'm not sure if MySQL converts it into a date or if I need to do it myself.
mysql_pconnect("mysql09.powweb.com", "foo", "foo") or die("Can't connect to MySQL Server");
mysql_select_db("news_database") or die("Can't find the MySQL database");
$insertquery = "INSERT INTO news_entries (entrydate, post) VALUES ($completedate, $completetext)";
$result = mysql_query($insertquery) or die("Couldn't add new post.");
$error = mysql_error();
print "$error";
mysql_close();
The table news_entries consists of three fields: entrydate (a date field), post (a text field), and id (an int). id is an auto-increment field and the primary key to guarantee uniqueness. In the example above, I don't try to set a value for id, but just let the auto-increment set it.
The connect and select_db goes fine, but when I try to run the query with mysql_query, I get my die message. mysql_error() returns nothing. Am I just making a syntax mistake here? The only thing I can think of is maybe the date field. I'm trying to insert a string into it (in the form (yyyy-mm-dd) and I'm not sure if MySQL converts it into a date or if I need to do it myself.