[PHP] Unknown column 'peterspeters' in 'where clause'
Hi All, the below code generates this error, Unknown column 'peterspeters' in 'where clause' mysql_select_db(status, $db); $username = $_POST[username]; $password = $_POST[password]; $result = mysql_query(SELECT customer_id FROM Customers WHERE customer_username = $username AND customer_password = $password) or die (mysql_error()); $myrow = mysql_fetch_row($result); $customer_id = $myrow[0]; $_SESSION['customer_id'] = $customer_id; ? /head body ?php echo 'SQL Query: '.$result.'br'; echo CustomerID = $customer_id; ? Cheers. Mark Sargent. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unknown column 'peterspeters' in 'where clause'
Hi, Wednesday, May 18, 2005, 4:27:34 PM, you wrote: MS Hi All, MS the below code generates this error, MS Unknown column 'peterspeters' in 'where clause' MS mysql_select_db(status, $db); MS $username = $_POST[username]; MS $password = $_POST[password]; MS $result = mysql_query(SELECT customer_id FROM Customers WHERE MS customer_username = $username AND customer_password = $password) or die MS (mysql_error()); MS $myrow = mysql_fetch_row($result); MS $customer_id = $myrow[0]; MS $_SESSION['customer_id'] = $customer_id; ? MS /head MS body MS ?php MS echo 'SQL Query: '.$result.'br'; MS echo CustomerID = $customer_id; ? MS Cheers. MS Mark Sargent. You need to put the variables in single quotes, otherwise mysql treats it as a column name. You should also escape the strings to be safe if magic_quotes are turned off in php.ini A bit like this: mysql_select_db(status, $db); $username = mysql_escape_string($_POST[username]); $password = mysql_escape_string($_POST[password]); $result = mysql_query( SELECT customer_id FROM Customers WHERE customer_username = '$username' AND customer_password = '$password') or die (mysql_error()); $myrow = mysql_fetch_row($result); $customer_id = $myrow[0]; $_SESSION['customer_id'] = $customer_id; -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unknown column 'peterspeters' in 'where clause'
If customer_username is a string (char, varchar, text etc.) then I guess it should be mysql_query(SELECT customer_id FROM Customers WHERE customer_username = \$username\ AND customer_password = \$password\) Prathap -- Original Message --- From: Mark Sargent [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wed, 18 May 2005 15:27:34 +0900 Subject: [PHP] Unknown column 'peterspeters' in 'where clause' Hi All, the below code generates this error, Unknown column 'peterspeters' in 'where clause' mysql_select_db(status, $db); $username = $_POST[username]; $password = $_POST[password]; $result = mysql_query(SELECT customer_id FROM Customers WHERE customer_username = $username AND customer_password = $password) or die (mysql_error()); $myrow = mysql_fetch_row($result); $customer_id = $myrow[0 ]; $_SESSION['customer_id'] = $customer_id; ? /head body ?php echo 'SQL Query: '.$result.'br'; echo CustomerID = $customer_id; ? Cheers. Mark Sargent. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- End of Original Message --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Unknown column 'peterspeters' in 'where clause'
hi Mark Unknown column 'peterspeters' in 'where clause' you're missing the quotes around (I guess) the password. you can kick yourself now :-p -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Unknown column 'peterspeters' in 'where clause'
I expect (indeed I sincerely hope) that customer_username AND customer_password columns are character datatypes. So it would be a good idea to put single quotes around the values you are trying to select from them. -Original Message- From: Mark Sargent [mailto:[EMAIL PROTECTED] Sent: 18 May 2005 07:28 To: php-general@lists.php.net Subject: [PHP] Unknown column 'peterspeters' in 'where clause' Hi All, the below code generates this error, Unknown column 'peterspeters' in 'where clause' mysql_select_db(status, $db); $username = $_POST[username]; $password = $_POST[password]; $result = mysql_query(SELECT customer_id FROM Customers WHERE customer_username = $username AND customer_password = $password) or die (mysql_error()); $myrow = mysql_fetch_row($result); $customer_id = $myrow[0]; $_SESSION['customer_id'] = $customer_id; ? /head body ?php echo 'SQL Query: '.$result.'br'; echo CustomerID = $customer_id; ? Cheers. Mark Sargent. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Gamma Global : Suppliers of HPCompaq, IBM, Acer, EPI, APC, Cyclades, D-Link, Cisco, Sun Microsystems, 3Com GAMMA GLOBAL (UK) LTD IS A RECOGNISED 'INVESTOR IN PEOPLE' AND AN 'ISO 9001 2000' REGISTERED COMPANY ** CONFIDENTIALITY NOTICE: This Email is confidential and may also be privileged. If you are not the intended recipient, please notify the sender IMMEDIATELY; you should not copy the email or use it for any purpose or disclose its contents to any other person. GENERAL STATEMENT: Any statements made, or intentions expressed in this communication may not necessarily reflect the view of Gamma Global (UK) Ltd. Be advised that no content herein may be held binding upon Gamma Global (UK) Ltd or any associated company unless confirmed by the issuance of a formal contractual document or Purchase Order, subject to our Terms and Conditions available from http://www.gammaglobal.com EOE ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php