Jump to content

Error, Query Failed... Why? (code inside)


aaricwon

Recommended Posts

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

<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,

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,

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.