Re: [PHP-DB] problem - query inside a function
My Comment bellow: On Wednesday 15 October 2003 14:38, Kirk Babb wrote: Hi, I'm having trouble with a query inside a function. I thought I'd written this so that the function would fail if email and zipcode supplied were not in the same row (trying to use those two things to identify the user), but I don't think that is what is happening because I can enter the wrong zipcode and it will return data based on the email. Any suggestions or corrections? Thanks! -Kirk [code snippet] function getEditData($email,$zipcode) { $sql = SELECT * FROM contact_info WHERE zipcode='$zipcode' AND email=\{$email}\; Change by $sql = SELECT * FROM contact_info WHERE zipcode='{$zipcode}' AND email='{$email}'; $query = mysql_query($sql); if (mysql_affected_rows()==0) { $this-sendResult(Fail,We do not have the given email and zipcode on file. Please go to the menu and start again.); } [end snippet] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] problem - query inside a function
From: Luis M Morales C [EMAIL PROTECTED] My Comment bellow: On Wednesday 15 October 2003 14:38, Kirk Babb wrote: Hi, I'm having trouble with a query inside a function. I thought I'd written this so that the function would fail if email and zipcode supplied were not in the same row (trying to use those two things to identify the user), but I don't think that is what is happening because I can enter the wrong zipcode and it will return data based on the email. Any suggestions or corrections? Thanks! -Kirk [code snippet] function getEditData($email,$zipcode) { $sql = SELECT * FROM contact_info WHERE zipcode='$zipcode' AND email=\{$email}\; Change by $sql = SELECT * FROM contact_info WHERE zipcode='{$zipcode}' AND email='{$email}'; That's not causing the problem. Both methods are valid. $query = mysql_query($sql); if (mysql_affected_rows()==0) { mysql_affected_rows() does not apply to SELECT queries. Perhaps you're meaning mysql_num_rows()? $this-sendResult(Fail,We do not have the given email and zipcode on file. Please go to the menu and start again.); } ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] problem - query inside a function
You guys might have valid points, but I think Kirk solved this problem to his satisfaction sometime yesterday. I can't speak for Kirk though. See: [PHP-DB] [CLARIFICATION on SOLUTION] Re: problem - query inside a function -Original Message- From: CPT John W. Holmes [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 10:57 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [PHP-DB] problem - query inside a function From: Luis M Morales C [EMAIL PROTECTED] My Comment bellow: On Wednesday 15 October 2003 14:38, Kirk Babb wrote: Hi, I'm having trouble with a query inside a function. I thought I'd written this so that the function would fail if email and zipcode supplied were not in the same row (trying to use those two things to identify the user), but I don't think that is what is happening because I can enter the wrong zipcode and it will return data based on the email. Any suggestions or corrections? Thanks! -Kirk [code snippet] function getEditData($email,$zipcode) { $sql = SELECT * FROM contact_info WHERE zipcode='$zipcode' AND email=\{$email}\; Change by $sql = SELECT * FROM contact_info WHERE zipcode='{$zipcode}' AND email='{$email}'; That's not causing the problem. Both methods are valid. $query = mysql_query($sql); if (mysql_affected_rows()==0) { mysql_affected_rows() does not apply to SELECT queries. Perhaps you're meaning mysql_num_rows()? $this-sendResult(Fail,We do not have the given email and zipcode on file. Please go to the menu and start again.); } ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] problem - query inside a function
Kirk, First, I'd recommend troubleshooting this function by doing the following: [code snippet] function getEditData($email,$zipcode) { $sql = SELECT * FROM contact_info WHERE zipcode='$zipcode' AND email=\{$email}\; echo $sql; //ADD THIS LINE //$query = mysql_query($sql); //if (mysql_affected_rows()==0) { // $this-sendResult(Fail,We do not have the given //email and zipcode //on file. Please go to the menu and start again.); } [end snippet] It SHOULD, repeat, SHOULD, depending on how you have your function implemented, just spit out the query string in the browser window for you. From there you can determine if the proper query string is being sent by the function. My guess would be that you need to add periods (concatenate) around the $email variable in the query string, but I'm not certain because I'm unfamiliar with how the curly braces are used in your code. $sql = SELECT * FROM contact_info WHERE zipcode='$zipcode' AND email=\.{$email}.\; Hope this helps. -Original Message- From: Kirk Babb [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 15, 2003 2:38 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] problem - query inside a function Hi, I'm having trouble with a query inside a function. I thought I'd written this so that the function would fail if email and zipcode supplied were not in the same row (trying to use those two things to identify the user), but I don't think that is what is happening because I can enter the wrong zipcode and it will return data based on the email. Any suggestions or corrections? Thanks! -Kirk [code snippet] function getEditData($email,$zipcode) { $sql = SELECT * FROM contact_info WHERE zipcode='$zipcode' AND email=\{$email}\; $query = mysql_query($sql); if (mysql_affected_rows()==0) { $this-sendResult(Fail,We do not have the given email and zipcode on file. Please go to the menu and start again.); } [end snippet] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php