aaricwon Posted February 28, 2008 Share Posted February 28, 2008 Anyone know why my Query is failing? <html> <head> <meta http-equiv="Content-Type" field_2="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .box { font-family: Arial, Helvetica, sans-serif; font-size: 12px; border: 1px solid #000000; } --> </style> </head> <body> <?php if(isset($_POST['save'])) { $order = $_POST['order']; $notes = $_POST['notes']; if(!get_magic_quotes_gpc()) { $order = addslashes($order); $notes = addslashes($notes); } include 'mysql_connect.php'; $query = "INSERT INTO daily_log (order, notes, date) VALUES ('$order', '$notes', NOW())"; mysql_query($query) or die('Error ,query failed'); echo "Order '$order' added to daily log"; } ?> <form method="post"> <table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center"> <tr> <td width="100"><b>Oracle Order</b></td> <td><input name="order" type="text" class="box" id="order"></td> </tr> <tr> <td width="100"><b>Notes</b></td> <td><textarea name="notes" cols="50" rows="10" class="box" id="notes"></textarea></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td colspan="2" align="center"><input name="save" type="submit" class="box" id="save" value="Save Daily Log"></td> </tr> </table> </form> </body> </html> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/93515-error-query-failed-why-code-inside/ Share on other sites More sharing options...
revraz Posted February 28, 2008 Share Posted February 28, 2008 You cant use DATE as a MySQL fieldname since it's reserved. Use backticks around it or better yet, change the name. Use mysql_error() after your querries as well. Link to comment https://forums.phpfreaks.com/topic/93515-error-query-failed-why-code-inside/#findComment-479113 Share on other sites More sharing options...
aaricwon Posted February 28, 2008 Author Share Posted February 28, 2008 what do you mean by ""? sorry if that is a dumb question... can you show me w/the code above? Also, as far as date... I just want the date to be automatically inserted... Link to comment https://forums.phpfreaks.com/topic/93515-error-query-failed-why-code-inside/#findComment-479122 Share on other sites More sharing options...
revraz Posted February 28, 2008 Share Posted February 28, 2008 Your MySQL Fieldname can't be the word DATE. Link to comment https://forums.phpfreaks.com/topic/93515-error-query-failed-why-code-inside/#findComment-479221 Share on other sites More sharing options...
uniflare Posted February 28, 2008 Share Posted February 28, 2008 <html> <head> <meta http-equiv="Content-Type" field_2="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .box { font-family: Arial, Helvetica, sans-serif; font-size: 12px; border: 1px solid #000000; } --> </style> </head> <body> <?php if(isset($_POST['save'])) { $order = $_POST['order']; $notes = $_POST['notes']; if(!get_magic_quotes_gpc()) { $order = addslashes($order); $notes = addslashes($notes); } include 'mysql_connect.php'; $query = "INSERT INTO daily_log (`order`, `notes`, `date`) VALUES ('$order', '$notes', ".time().")"; mysql_query($query) or die('Error ,query failed'); echo "Order '$order' added to daily log"; } ?> <form method="post"> <table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center"> <tr> <td width="100"><b>Oracle Order</b></td> <td><input name="order" type="text" class="box" id="order"></td> </tr> <tr> <td width="100"><b>Notes</b></td> <td><textarea name="notes" cols="50" rows="10" class="box" id="notes"></textarea></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td colspan="2" align="center"><input name="save" type="submit" class="box" id="save" value="Save Daily Log"></td> </tr> </table> </form> </body> </html> always use a unix timestamp when storing dates into mysql. use date("<format>",$timestamp); to get a date using the timestamp. hope this helps, Link to comment https://forums.phpfreaks.com/topic/93515-error-query-failed-why-code-inside/#findComment-479248 Share on other sites More sharing options...
revraz Posted February 28, 2008 Share Posted February 28, 2008 I wouldn't agree with that myself. I personally do like unix timestamps, but there is nothing at all wrong with using MySQL datetime formats. always use a unix timestamp when storing dates into mysql. use date("<format>",$timestamp); to get a date using the timestamp. hope this helps, Link to comment https://forums.phpfreaks.com/topic/93515-error-query-failed-why-code-inside/#findComment-479287 Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2008 Share Posted February 28, 2008 date is a data type. It is not a reserved keyword - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html and it can be used as a table or column name. Putting the mysql_error() function into the or die() statement will tell you why the query is failing. Using a mysql DATE or DATETIME data type allows you greater flexibility (you can use about 20-30 date/time functions directly in a query and you are not continually needed to call the php date() function to convert to a human readable format) that using a Unix timestamp requires extra coding to accomplish, which slows everything down. Link to comment https://forums.phpfreaks.com/topic/93515-error-query-failed-why-code-inside/#findComment-479291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.