Jump to content

[SOLVED] Can't find simple error


SocomNegotiator

Recommended Posts

Here is my code:

$order_number = $_POST['order_number'];

$db->query("SELECT * FROM `order` ORDER BY order_number DESC LIMIT 1") or die(mysql_error());
$number = $db->fetch_array();
$num = 1;
if($num = $number['order_number'])
	$num = $number['order_number'] + 1;
elseif($number['order_number'] == "")
	$num = 1;
else
	$num = $num;

$res = mysql_query('SELECT * FROM `order` WHERE order_number = '.$order_number) or die(mysql_error());
while($r = mysql_fetch_array($res)){
$inserted=$db->query("INSERT INTO `order` (`order_number`,`pre_order_id` , `item_id` , `amount` , `user_id` )  VALUES (".$num.",".$r['id'].", ".$r['item_id'].", ".$r['amount'].", ".$r['user_id'].")") or die (mysql_error());

 

This is the error I get:

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 '' at line 1

 

The error is not much help at all...

Link to comment
Share on other sites

Here is the code for the whole page...

 

<?php
if(!defined('IN_SCRIPT')) header('Location: ');
$skin->set_global_vars(array('page_title' => 'order'));
if(!$user->logged_in())	{
header("Location: {$_config['HTTP_INDEX']}?page=account.login");
$skin->buffer_drop_rest();
}


//BEGIN: Form Processing:
if(isset($_POST['submit']))
{

$order_number = $_POST['order_number'];

$db->query("SELECT * FROM `order` ORDER BY order_number DESC LIMIT 1") or die(mysql_error());
$number = $db->fetch_array();
$num = 1;
if($num = $number['order_number'])
	$num = $number['order_number'] + 1;
elseif($number['order_number'] == "")
	$num = 1;
else
	$num = $num;

$res = mysql_query('SELECT * FROM `order` WHERE order_number = '.$order_number) or die(mysql_error());
while($r = mysql_fetch_array($res)){
$inserted=$db->query("INSERT INTO `order` (`order_number`,`pre_order_id` , `item_id` , `amount` , `user_id` )  VALUES (".$num.",".$r['id'].", ".$r['item_id'].", ".$r['amount'].", ".$r['user_id'].")") or die (mysql_error());

// track the id's of the new inserts
$insert_ids[] = mysql_insert_id();
}
if($error){
echo $error;
// remove any rows that HAVE been inserted from the pre_order table
$ids = implode("', '", $insert_ids);
  if($inserted){
  echo "Your order has been re-submitted.";
  } else {
  echo "Could not re-submit your order Error: ".mysql_error();
  }
} else {
  if($inserted){
  echo "Your order has been re-submitted.";
  } else {
  echo "Could not re-submit your order Error: ".mysql_error();
  }
}

}
?>




<div id="">

<div id='case'>

<?php
$user_id = $user->inf['id'];
$db->query('SELECT * FROM item ORDER BY date DESC') or die(mysql_error());
$row = $db->fetch_array();

$query = "SELECT * FROM `order` WHERE user_id=".$user_id." ORDER BY order_number, date";
$result = mysql_query($query) or die (mysql_error());

$db->query('SELECT item.id, item.name, item.description, order.id, order.amount, order.user_id, order.order_number FROM `order` LEFT JOIN `item` ON order.item_id = item.id') or die(mysql_error());
$iteminf = $db->fetch_array();

$current_order = '';
echo "<table border='1' cellpadding='5' cellspacing='5'>\n";

while ($record = mysql_fetch_assoc($result))
{
    //If first record for a new order display the header rows
    if ($current_order!=$record['order_number'])
    {
       $current_order = $record['order_number'];
	echo "<tr><td colspan='3'><form id='resubmit_order' action='?page=order' method='post'><input type='hidden' name='order_number' value=".$record['order_number']."/><center><input type='submit' name='submit' value='Re-Submit Order #".$record['order_number']."'/></center>
	</form></td></tr>";
        echo "<tr>\n";
        echo "<td colspan='4 align='left'><b>Order # $current_order:</b></td>\n";
        echo "</tr><tr><td>Item ID</td><td>Quantity</td><td>Date</td>\n";
        echo "</tr>\n";
    }

    //Display the record data
    echo "<tr>\n";
    echo "<td>" . $iteminf['name'] . "</td>\n";
    echo "<td>" . $record['amount'] . "</td>\n";
    echo "<td>" . $record['date'] . "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>

</div>
</div>

<br />
<br />


Link to comment
Share on other sites

I did it...and this is the line of code that it said the error was on. I also tested my variable again just to make sure and the variable is working like it is supposed too. The only problem I can think of is that the items of the order are stored in the order table and more than one item can have the same order_number...but that should not make any difference

 

$res = mysql_query('SELECT * FROM `order` WHERE order_number = '.$order_number) or die(mysql_error()."at Query: 26");

 

 

Maybe in your or die(mysql_error()); you should have

 

or die(mysql_error()."<br>Query Was: "$query);

 

or die(mysql_error()."<br>at Query: 21"); (enter anything to identify the line)

 

 

Link to comment
Share on other sites

I get this error now...

 

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 '' at line 1

SELECT * FROM `order` WHERE order_number = 1/

 

You notice that the order_number is 1, and that is the order I clicked on. This order only has one item under it. However the other order has 2 items under it. I am thinking the query does not know what to do with the multiple items that have the same order_number

 

 

Change that to....

 

$sql = 'SELECT * FROM `order` WHERE order_number = ' . $order_number;
$res = mysql_query($sql) or die(mysql_error() . "<br />$sql");

 

What do you get?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.