ged415 Posted March 9, 2009 Share Posted March 9, 2009 I am working with MySQL and a PHP script to lookup a user ID and password from a database. I can not however get it to return any results. it just says no such email. I can though see the database and the email address is there. If I change the connection parameters I do get an error so it seems I am connecting. The database only has the three fields. Here is the code if someone see's my mistake any help would be greatly appreciated, thanks. <?php @mysql_connect("localhost", "login", "password!") or die("Cannot connect to DB!"); @mysql_select_db("database") or die("Cannot select DB!"); $query="SELECT email_webuser, id_webuser, passwd_webuser FROM b2bpasswords WHERE email_webuser=''".$email_webuser."''"; $r = mysql_query($query); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ print "no such email in the system. please try again."; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/148594-mysql-database-lookup/ Share on other sites More sharing options...
Adam Posted March 9, 2009 Share Posted March 9, 2009 Where does "$email_webuser" come from? Try using: $r = mysql_query($query) or die(mysql_error()); Adam Quote Link to comment https://forums.phpfreaks.com/topic/148594-mysql-database-lookup/#findComment-780317 Share on other sites More sharing options...
kickstart Posted March 9, 2009 Share Posted March 9, 2009 Hi Appears to be too many single quotes around the variable. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148594-mysql-database-lookup/#findComment-780319 Share on other sites More sharing options...
ged415 Posted March 9, 2009 Author Share Posted March 9, 2009 This is coming fom an HTML form that has one field, emial_webuser, with a POST action against forgot.php I modified two lines to now be $query="SELECT email_webuser, id_webuser, passwd_webuser FROM b2bpasswords WHERE email_webuser='".$email_webuser."'"; $r = mysql_query($query) or die(mysql_error()); I still get no such email in the system. please try again. Quote Link to comment https://forums.phpfreaks.com/topic/148594-mysql-database-lookup/#findComment-780329 Share on other sites More sharing options...
Adam Posted March 9, 2009 Share Posted March 9, 2009 Add: $email_webuser = mysql_real_escape_string($_POST['email_webuser']); ... somewhere before the query in your file. Adam Quote Link to comment https://forums.phpfreaks.com/topic/148594-mysql-database-lookup/#findComment-780333 Share on other sites More sharing options...
kickstart Posted March 9, 2009 Share Posted March 9, 2009 Hi For safety the above suggestion is good. Echo out $query after you have set it up and check what has been generated. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148594-mysql-database-lookup/#findComment-780355 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.