smithmr8 Posted February 18, 2008 Share Posted February 18, 2008 This is supposed to Add an update to a mysql Table called 'Updates'. The fields are 'date' and 'update'. Update is filled with the update text from the $_POST Date is filled with the time/date at that point. My problem is that its not inserting anything into the table. It appears to work, yet doesn't insert anything. Can you help ? <b>Add Update</b><br> <center><form method="POST" action="area1.php?step=add"> Update Content<br> <textarea rows="3" name="update" cols="40"></textarea><br> <input type="submit" value="Add" name="B1"> </form></center> <?php if($_GET['step'] == 'add'){ $updatecontent = $_POST['update']; $date = date("d/m H:i:sA"); $sql = "INSERT INTO `updates` (date, update) VALUES ('$date', '$updatecontent')"; mysql_query($sql); echo "<center>Update Added Successfully</center>"; } ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 18, 2008 Share Posted February 18, 2008 You need to try and catch the error at the end of your query: mysql_query($sql)or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
aschk Posted February 18, 2008 Share Posted February 18, 2008 I endeavour to say your date format is probably wrong. Default date format for MySQL is YYYY-MM-DD. If you are using a date or datetime or timestamp column this query will fail due to format. So i think you should be doing this: $date = date("Y-m-d"); Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 18, 2008 Author Share Posted February 18, 2008 I put that in, but it does not display an error. It just displays "Update Added Successfully". Quote Link to comment Share on other sites More sharing options...
soycharliente Posted February 18, 2008 Share Posted February 18, 2008 I have had problems in the past when I used 'date' as a field name. Try changing it to 'thedate' and see if it works then. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 18, 2008 Share Posted February 18, 2008 I didn't even catch the "date" field. You can put backsticks (`) around it and it will be fine. $sql = "INSERT INTO `updates` (`date`, update) VALUES ('$date', '$updatecontent')"; Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 18, 2008 Author Share Posted February 18, 2008 <?php if($_GET['step'] == 'add'){ $updatecontent = $_POST['update']; $thedate = date("d/m H:i:sA"); $sql = "INSERT INTO `updates` (`date`, update) VALUES ('$thedate', '$updatecontent')" or die(mysql_error()); mysql_query($sql); echo "<center>Update Added Successfully</center>"; } ?> I've got this now, but its still not working. Tried the backsticks. Tried changing the field name. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 18, 2008 Share Posted February 18, 2008 You still didn't add the die statement to the end of your query...that is what is going to give you the error you need. mysql_query($sql)or die(mysql_error() . "<p>With Query<br>$sql"); Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 18, 2008 Author Share Posted February 18, 2008 Oh.. I see. I put that in and received this error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update) VALUES ('18/02 18:18:23PM', '55')' at line 1 With Query INSERT INTO `updates` (`thedate`, update) VALUES ('18/02 18:18:23PM', '55') Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 18, 2008 Author Share Posted February 18, 2008 I put backsticks around update aswell, and its now working. Thanks alot. Quote Link to comment Share on other sites More sharing options...
rlindauer Posted February 18, 2008 Share Posted February 18, 2008 Update is a reserved word in MySQL. http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 18, 2008 Share Posted February 18, 2008 Which means you are going to have to put backsticks around the word "update" as well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.