josephusofkartenon Posted May 23, 2007 Share Posted May 23, 2007 i have been going nuts for 2 months now trying to get 1 line of PHP code to work. its simple and straight forward but doesnt wish to work for somereason. a little background before i post it here. i have another php working to enter info into my table and it works fine, however to cross reference that info doesnt work. it eitheer ALWAYS gives me a result or NEVER gives me a result and it is driving me nuts. please understnand if i dont list the passwords and connections. the connections connect and are fine, the "post" info from the form is fine. everytnhing but the result works. i am starting it for a password and login script but until i can get the fiundamentals working, no need to work ont he rest. thank you for any help. my mysql shows the querys but shows them as SELECT FROM users WHERE 1. so here is the code if anyone can see the problems, please let me know. and i have tried many different formats from investiugating online to no avail. thank you. here is the code. the "echos" are merely for trouble shooting. <?php $conn = mysql_connect("localhost", name, password) or die("can not connect"); $db = mysql_select_db(database, $conn) or die ("can not connect"); $username = $_POST["username"]; $password = $_POST["password"]; echo $username; echo; echo $password; echo; $result = mysql_query("SELECT * FROM users WHERE uname = '$username' AND pword = '$password' ",$conn) or die ("Login and/or Password not found."); echo $result; echo "good job"; mysql_close($conn); ?> thanks for any help. Joey D. Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/ Share on other sites More sharing options...
flappy_warbucks Posted May 23, 2007 Share Posted May 23, 2007 Well i would do this: <?php $conn = mysql_connect("localhost", name, password) or die("can not connect"); $db = mysql_select_db(database, $conn) or die ("can not connect"); $username = $_POST["username"]; $password = $_POST["password"]; echo $username; echo $password; $result = mysql_query("SELECT * FROM users WHERE uname = \"". $username. "\" AND pword = \""$password. "\") or die ("Login and/or Password not found."); echo $result; echo "good job"; mysql_close($conn); ?> I removed the ,$CONN from there as i didn't see what it done... maybe someone less thick then me can figure it out... But i don't see the point of blank echo commands... what are they trying to do??? from looking at ur code that's all i can figure out! Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260355 Share on other sites More sharing options...
Guest Posted May 23, 2007 Share Posted May 23, 2007 Try This $conn = mysql_connect("localhost", name, password) or die("can not connect"); $db = mysql_select_db(database, $conn) or die ("can not connect"); $username = $_POST["username"]; $password = $_POST["password"]; echo $username; echo $password; $result = mysql_query("SELECT * FROM users WHERE uname = '$username' AND pword = '$password' ",$conn) or die ("Login and/or Password not found."); $row = mysql_fetch_array($result); $uname = $row['uname']; echo "$uname"; mysql_close($conn); Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260358 Share on other sites More sharing options...
flappy_warbucks Posted May 23, 2007 Share Posted May 23, 2007 Try This $conn = mysql_connect("localhost", name, password) or die("can not connect"); $db = mysql_select_db(database, $conn) or die ("can not connect"); $username = $_POST["username"]; $password = $_POST["password"]; echo $username; echo $password; $result = mysql_query("SELECT * FROM users WHERE uname = '$username' AND pword = '$password' ",$conn) or die ("Login and/or Password not found."); $row = mysql_fetch_array($result); $uname = $row['uname']; echo "$uname"; mysql_close($conn); i knew i was forgetting something... loud trance music and 6 beers kinda kills the skills ;-) hhahaha Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260360 Share on other sites More sharing options...
Guardian-Mage Posted May 23, 2007 Share Posted May 23, 2007 If the problem is solved, please clicked solved Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260372 Share on other sites More sharing options...
josephusofkartenon Posted May 24, 2007 Author Share Posted May 24, 2007 thanks guys. i tried both suggestions. #1 gives syntax error and #2 still does the same thing. thank you guys. Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260382 Share on other sites More sharing options...
josephusofkartenon Posted May 24, 2007 Author Share Posted May 24, 2007 however i did find that #2 did make a minor change. if the name a nd pword match, it will display the name and pword, however, if it doesnt it does not display those items however it still doesnt "die" it continues to the echo "good job". i just cant get it to die. Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260385 Share on other sites More sharing options...
hitman6003 Posted May 24, 2007 Share Posted May 24, 2007 the "die" will only be executed if the mysql query fails...not if it returns a result meaning that the username and password were not found. $conn = mysql_connect("localhost", name, password) or die("can not connect"); $db = mysql_select_db(database, $conn) or die ("can not connect"); $username = $_POST["username"]; $password = $_POST["password"]; $result = mysql_query("SELECT id FROM users WHERE uname = '$username' AND pword = '$password' ", $conn) or die ("Error in query: " . mysql_error()); if (mysql_num_rows($result) == 1) { echo "Username / Password combo found"; } else if (mysql_num_rows($result) > 1) { echo "Username / Password error - multiple entries"; } else { echo "Username / Password combo not found"; } mysql_close($conn); Note the difference in the "die" statement. Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260441 Share on other sites More sharing options...
josephusofkartenon Posted May 24, 2007 Author Share Posted May 24, 2007 thank you very very much. that did it. i am learning php now. from a "basic" background. thank you very much. i misunderstood how the die worked. thank you for teaching me. i am indebted. Quote Link to comment https://forums.phpfreaks.com/topic/52731-solved-help/#findComment-260452 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.