Hi, I'm getting this very weird error: sql_email2: 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 Code (markup): when I run this script... I don't know what's wrong with it!!! <?php /* File: email.inc * Desc: Emails the shopper and orders@jogrammah.com. */ $connect = connect_to_db("Vars.inc"); $query = 'SELECT * FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . '"'; $result = mysql_query($query) or die("sql_email: ".mysql_error()); $numrows = mysql_num_rows($result); if ($numrows) { $itemsmessage = "You ordered:\n\n"; while ($row = mysql_fetch_assoc($result)) { $_SESSION['order_number'] = $ordernumber; $query = 'SELECT name FROM Food WHERE catalog_number = (SELECT catalog_number FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . ')"'; $result = mysql_query($query) or die("sql_email2: ".mysql_error()); while ($row = mysql_fetch_array($result)){ $blah = $row['name']; echo $row['name']; echo "<br>"; } $itemsmessage = $itemsmessage . "Item number " . $row['item_number'] . ":" . " Item name: " . $blah . " qty: " . $row['quantity'] . "\n"; } }; $emailto = $_SESSION['email']; $orderID = $_SESSION['order_number']; $subject = "Your order number ".$_SESSION['order_number']." -- JoGrammah.com"; $from = "From: orders@jogrammah.com"; $from2 = "From: ".$emailto; $ship_name = $_SESSION['ship_name']; $ship_street = $_SESSION['ship_street']; $ship_city = $_SESSION['ship_city']; $state = $_SESSION['ship_state']; $ship_zip = $_SESSION['ship_zip']; $phone = $_SESSION['phone']; $cc_number = $_SESSION['cc_number']; $ordertotal = $_SESSION['order_total']; $noitemsordered = $_SESSION['n_items']; $subject2 = "Order # ".$_SESSION['order_number'].": ".$_SESSION['ship_name']; $message = "Thank you for ordering at JoGrammah.com!\nYou ordered $noitemsordered item(s).Your order costs "."$"."$ordertotal.$itemsmessage\nYour order will be shipped to:\n\n$ship_name\n$ship_street\n$ship_city, $state\n$ship_zip\n\nSince our store is not fully completed, you may be contacted at $phone for further details concerning your order.\n\nSincerely,\n-JoGrammah.com staff"; $message2 = "ORDER NUMBER $orderID \n\nShip to:\n$ship_name\n$ship_street\n$ship_city, $ship_state\n\nPhone number: $phone\nEmail: $emailto";mail($emailto, $subject, $message, $from);mail("orders@jogrammah.com", $subject2, $message2, $from2); ?> PHP: I don't understand this... You see where the second "or die" error catch is? That's what's catching the error on line 1. But, if there really was an error on line 1, then why didn't my first error "catcher" catch it???
The 'line 1' is not referencing line 1 in your code: it's line 1 in the SQL query that has the error. I would say it's your use of subselects (or whatever they're called): either the syntax itself is incorrect, or the version of MySQL you're using doesn't support it. Maybe.
You close the subquery brackets inside the "" for the value in the WHERE condition $query = 'SELECT name FROM Food WHERE catalog_number = (SELECT catalog_number FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . ')"'; PHP: should be $query = 'SELECT name FROM Food WHERE catalog_number = (SELECT catalog_number FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . '")'; PHP: