Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No error produced, but data not added to database.

Status
Not open for further replies.

Siberd

Technical User
Jun 24, 2001
35
0
0
US
Hello all,

I am having trouble writing to a database using php.

No errors are produced, but the data is not being writtern to the database.

here is the code:
$user = 'admin';
$db = 'forum';
$link = mysql_connect ("localhost", $user);
if (! $link)
die("</table><font color=red>Failed to open connection to SQL database</font>");
mysql_select_db($db)
or die ("</table><font color=red>Failed to open $db:" .mysql_error() ."</font>");

$query = "INSERT INTO forum (author, lastpost, replies, topic, post_date, message_body) values ('$_REQUEST[author]', now, 0, '$_REQUEST[topic]', now, '$_REQUEST[body]')";
mysql_query($query, $link)
or die ('<font color=red>Failed to write to database: '.mysql_error() .'</font>');
mysql_close($link);

I can't see anything wrong in there, anyone have any ideas?

Many thanks.



/Sib
programmer in the making
icq: 44167565
e-mail: siberdude@ntlworld.com
 
If you're trying to insert the current date, you should be using the function now() in your query.

Have you tried printing the query to the browser and copying-and-pasting it to your preferred MySQL admin tool?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ha! table column name lastpost doesn't exist. And yeah, your right, it should have been now().
I wonder why I didn't get the SQL error printed to the browser.. intresting.

/Sib
programmer in the making
icq: 44167565
e-mail: siberdude@ntlworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top