
February 1st, 2005, 08:00 AM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 1
Time spent in forums: 15 m 37 sec
Reputation Power: 0
|
|
|
INSERT not working in PHP4
Hi, I have been trying to insert records into the database using the following bit of code.
PHP Code:
$sql = "INSERT INTO news (`post_title`,`post_body`,`post_date`,`post_aid`) VALUES ('" . $_POST['title'] . "','" . $_POST['sub_news'] . "','" . date("l dS of F Y",time()) . "','" . $_SESSION['logged_in'] . "')"; echo $sql . "<br />"; $result = mysql_result($sql) or die(mysql_error());
as you can see i 'echo' the sql query to check it is ok and has all the information from the variables in.
This works fine and the query ends up looking something like this.
PHP Code:
INSERT INTO news (`post_title`,`post_body`,`post_date`,`post_aid`) VALUES ('test','test','Tuesday 01st of February 2005','1')
I ran the query manually using the mysql command line and it inserted the record fine.
Why could this not be working in PHP. I have been using SELECT queries in PHP and they are working fine.
the mysql_error() in the code above returns nothing.
|