[SOLVED] php syntax error? in retrieving data from mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wsmeyer
Forum Newbie
Posts: 6
Joined: Fri Aug 27, 2004 8:28 pm
Location: Los Angeles

php syntax error? in retrieving data from mysql

Post 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))
&#123;
echo("<p>Message sent!</p>");
&#125;
else
&#123;
echo("<p>Message delivery failed...</p>");
&#125;
Any help would be appreciated!

William.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you sure $to was filled with something?
wsmeyer
Forum Newbie
Posts: 6
Joined: Fri Aug 27, 2004 8:28 pm
Location: Los Angeles

Post 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&#1111;"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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

add this after your fetch call:

Code: Select all

var_dump($sSQL_t,$to,$rs);
and post the results, please.
wsmeyer
Forum Newbie
Posts: 6
Joined: Fri Aug 27, 2004 8:28 pm
Location: Los Angeles

Post by wsmeyer »

Code: Select all

if(@$_POST&#1111;"act"]=="tracking")&#123; 
      do_stock_management(trim($_POST&#1111;"id"])); 
      if(trim($_POST&#1111;"authcode"]) != "1ZA918R503") 
$sSQL = "UPDATE orders set ordExtra2='" . mysql_escape_string(trim($_POST&#1111;"authcode"])) . "',ordStatus=6 WHERE ordID=" . $_POST&#1111;"id"];      mysql_query($sSQL) or print(mysql_error()); 
mysql_query($sSQL) or die(mysql_error()); 
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $rs&#1111;"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)) 
&#123; 
echo("<p>Message sent!</p>"); 
&#125; 
else 
&#123; 
echo("<p>Message delivery failed...</p>"); 
&#125;
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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where's $rs['OrdID'] set?
wsmeyer
Forum Newbie
Posts: 6
Joined: Fri Aug 27, 2004 8:28 pm
Location: Los Angeles

Post by wsmeyer »

I've palying with it since posting and have this now

Code: Select all

if(@$_POST&#1111;"act"]=="tracking")&#123; 
do_stock_management(trim($_POST&#1111;"id"])); 
if(trim($_POST&#1111;"authcode"]) != "1ZA918R503") 
echo 'authcode = ' . $_POST&#1111;"authcode"] . '<br> 
         id = ' . $_POST&#1111;"id"] . '<br> 
         ordEmail = ' . $rs&#1111;"ordEmail"] . '<P>'; 
$sSQL = "UPDATE orders set ordExtra2='" . mysql_escape_string(trim($_POST&#1111;"authcode"])) . "',ordStatus=6 WHERE ordID=" . $_POST&#1111;"id"]; 
$result1= mysql_query($sSQL) or die('Query 1:<br />' .mysql_error());
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $rs&#1111;"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)) 
&#123; 
echo("<p>Message sent!</p>"); 
&#125; 
else 
&#123; 
echo("<p>Message delivery failed...</p>"); 
&#125;
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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where is $rs created? why is it $rs['id'] instead of $_POST['id'] ??
wsmeyer
Forum Newbie
Posts: 6
Joined: Fri Aug 27, 2004 8:28 pm
Location: Los Angeles

Post by wsmeyer »

hopefully this will clear some of that up

Code: Select all

if(@$_POST&#1111;"act"]=="tracking")&#123; 
do_stock_management(trim($_POST&#1111;"id"])); 
if(trim($_POST&#1111;"authcode"]) != "1ZA918R503")  
$sSQL = "UPDATE orders set ordExtra2='" . mysql_escape_string(trim($_POST&#1111;"authcode"])) . "',ordStatus=6 WHERE ordID=" . $_POST&#1111;"id"]; 
$result1= mysql_query($sSQL) or die('Query 1:<br />' .mysql_error());
$sSQL_t = "SELECT ordEmail FROM orders WHERE ordID=" . $_POST&#1111;"id"]; 
$result = mysql_query($sSQL_t) or die(mysql_error());
echo 'authcode = ' . $_POST&#1111;"authcode"] . '<br> 
         id = ' . $_POST&#1111;"id"] . '<br> 
         ordEmail = ' . $rs&#1111;"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)) 
&#123; 
echo("<p>Message sent!</p>"); 
&#125; 
else 
&#123; 
echo("<p>Message delivery failed...</p>"); 
&#125;
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);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_fetch_row.. misspelled :P
wsmeyer
Forum Newbie
Posts: 6
Joined: Fri Aug 27, 2004 8:28 pm
Location: Los Angeles

Post 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.
Post Reply