Page 1 of 1
php syntax error? in retrieving data from mysql
Posted: Fri Aug 27, 2004 8:28 pm
by wsmeyer
The code I am modifying is the order administration page of a shopping cart. This portion writes the tracking # to the database and emails the tracking # to the customer. If instead of trying to grab the email address from the database I hard code $to=
wsmeyer@atitec.com; everything else works perfectly but as shown below the email bounces with no "to"
Code: Select all
if(@$_POSTї"act"]=="tracking"){
do_stock_management(trim($_POSTї"id"]));
if(trim($_POSTї"authcode"]) != "1ZA918R503")
$sSQL = "UPDATE orders set ordExtra2='" . mysql_escape_string(trim($_POSTї"authcode"])) . "',ordStatus=6 WHERE ordID=" . $_POSTї"id"]; mysql_query($sSQL) or print(mysql_error());
mysql_query($sSQL) or die(mysql_error());
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $rsї"OrdID"];
$result = mysql_query($sSQL_t) or die(mysql_error());
list($to) = msyql_fetch_row($result);
$tn = "$authcode";
$subject = "Your order has been shipped";
$body = "http://www.chaleur.com/tracking.php?trackno=$tn";
$headers = "From: " . "Chaleur.com" . " <" . "sales@chaleur.com" . ">\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers))
{
echo("<p>Message sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
Any help would be appreciated!
William.
Posted: Fri Aug 27, 2004 8:58 pm
by feyd
are you sure $to was filled with something?
Posted: Fri Aug 27, 2004 9:42 pm
by wsmeyer
I'm not sure what you are asking, when I replace this portion
Code: Select all
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $rsї"OrdID"];
$result = mysql_query($sSQL_t) or die(mysql_error());
list($to) = msyql_fetch_row($result);
with $to="
wsmeyer@atitec.com"
it does what I want but of course the email comes to me, I have verified that the email address I want is in the database "ordEmail" but my query is not pulling it.
William.
Posted: Fri Aug 27, 2004 10:00 pm
by feyd
add this after your fetch call:
and post the results, please.
Posted: Fri Aug 27, 2004 10:26 pm
by wsmeyer
Code: Select all
if(@$_POSTї"act"]=="tracking"){
do_stock_management(trim($_POSTї"id"]));
if(trim($_POSTї"authcode"]) != "1ZA918R503")
$sSQL = "UPDATE orders set ordExtra2='" . mysql_escape_string(trim($_POSTї"authcode"])) . "',ordStatus=6 WHERE ordID=" . $_POSTї"id"]; mysql_query($sSQL) or print(mysql_error());
mysql_query($sSQL) or die(mysql_error());
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $rsї"OrdID"];
$result = mysql_query($sSQL_t) or die(mysql_error());
list($to) = msyql_fetch_row($result);
var_dump($sSQL_t,$to,$rs);
$tn = "$authcode";
$subject = "Your order has been shipped";
$body = "http://www.chaleur.com/tracking.php?trackno=$tn";
$headers = "From: " . "Chaleur.com" . " <" . "sales@chaleur.com" . ">\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers))
{
echo("<p>Message sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
returns the same result
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
William.
Posted: Fri Aug 27, 2004 10:38 pm
by feyd
where's $rs['OrdID'] set?
Posted: Fri Aug 27, 2004 10:56 pm
by wsmeyer
I've palying with it since posting and have this now
Code: Select all
if(@$_POSTї"act"]=="tracking"){
do_stock_management(trim($_POSTї"id"]));
if(trim($_POSTї"authcode"]) != "1ZA918R503")
echo 'authcode = ' . $_POSTї"authcode"] . '<br>
id = ' . $_POSTї"id"] . '<br>
ordEmail = ' . $rsї"ordEmail"] . '<P>';
$sSQL = "UPDATE orders set ordExtra2='" . mysql_escape_string(trim($_POSTї"authcode"])) . "',ordStatus=6 WHERE ordID=" . $_POSTї"id"];
$result1= mysql_query($sSQL) or die('Query 1:<br />' .mysql_error());
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $rsї"id"];
$result = mysql_query($sSQL_t) or die(mysql_error());
list($to) = msyql_fetch_row($result);
$tn = "$authcode";
$subject = "Your order has been shipped";
$body = "http://www.chaleur.com/tracking.php?trackno=$tn";
$headers = "From: " . "Chaleur.com" . " <" . "sales@chaleur.com" . ">\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers))
{
echo("<p>Message sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
which returns this
authcode = 1458
id = 709
ordEmail =
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
authcode is the tracking # and id is the ordID number
William.
Posted: Fri Aug 27, 2004 11:03 pm
by feyd
where is $rs created? why is it $rs['id'] instead of $_POST['id'] ??
Posted: Fri Aug 27, 2004 11:15 pm
by wsmeyer
hopefully this will clear some of that up
Code: Select all
if(@$_POSTї"act"]=="tracking"){
do_stock_management(trim($_POSTї"id"]));
if(trim($_POSTї"authcode"]) != "1ZA918R503")
$sSQL = "UPDATE orders set ordExtra2='" . mysql_escape_string(trim($_POSTї"authcode"])) . "',ordStatus=6 WHERE ordID=" . $_POSTї"id"];
$result1= mysql_query($sSQL) or die('Query 1:<br />' .mysql_error());
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $_POSTї"id"];
$result = mysql_query($sSQL_t) or die(mysql_error());
echo 'authcode = ' . $_POSTї"authcode"] . '<br>
id = ' . $_POSTї"id"] . '<br>
ordEmail = ' . $rsї"ordEmail"] . '<P>';
list($to) = msyql_fetch_row($result);
$tn = "$authcode";
$subject = "Your order has been shipped";
$body = "http://www.chaleur.com/tracking.php?trackno=$tn";
$headers = "From: " . "Chaleur.com" . " <" . "sales@chaleur.com" . ">\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers))
{
echo("<p>Message sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
returns
authcode = 789
id = 709
ordEmail =
Fatal error: Call to undefined function: msyql_fetch_row() in /home/wsmeyer/public_html/vsadmin/inc/incorders.php on line 479
line 479 is
Code: Select all
list($to) = msyql_fetch_row($result);
Posted: Fri Aug 27, 2004 11:36 pm
by feyd
mysql_fetch_row.. misspelled

Posted: Sat Aug 28, 2004 12:33 am
by wsmeyer
I cannot believe how long I have been staring at this and how many different things I tried and it was just a spelling mistake all along!
Thanks for all your help!
William.