botlife Posted September 21, 2008 Share Posted September 21, 2008 I successfully made a registration page that updates to a mysql database. My problem is my login verification page. I am trying to echo the user's name from the database and it isn't working. $reg_email = $_POST[$reg_email]; $reg_pass = $_POST[$reg_pass]; $query = " SELECT * FROM login WHERE reg_email='$reg_email' AND reg_pass='$reg_pass' "; $result = mysql_query($query); $num = mysql_num_rows($result); if (!$result) { echo "CRAP!"; } while ($row = mysql_fetch_array($result)) { echo $row['reg_firstname']; } Please help, I am sure I am doing something very simple wrong. Quote Link to comment Share on other sites More sharing options...
benphp Posted September 21, 2008 Share Posted September 21, 2008 I'm assuming you get an error, though I can't tell by your post. If so, what's the error? If not, what's the problem? If it's a sql error, print $query; and see if your sql is bad. Quote Link to comment Share on other sites More sharing options...
botlife Posted September 21, 2008 Author Share Posted September 21, 2008 Not getting an errors at all. It just isn't printing the variable reg_firstname. I can see it in the database and everything is correct. Quote Link to comment Share on other sites More sharing options...
benphp Posted September 21, 2008 Share Posted September 21, 2008 can you print echo $row['reg_email']; or some other field? Also, print your SQL and run it in a terminal window in MySQL - if it doesn't work there, then the problem isn't in your PHP code - it's in the db or your SQL. Quote Link to comment Share on other sites More sharing options...
benphp Posted September 21, 2008 Share Posted September 21, 2008 this also comes in handy: $numrows = mysql_num_rows($result); print $numrows; lets you know if the record was found or not - in case you don't have terminal access. Quote Link to comment Share on other sites More sharing options...
botlife Posted September 21, 2008 Author Share Posted September 21, 2008 This is the output I am getting - SELECT * FROM login WHERE reg_email='' AND reg_pass='' 0 $reg_email = $_POST[$reg_email]; $reg_pass = $_POST[$reg_pass]; $query = " SELECT * FROM login WHERE reg_email='$reg_email' AND reg_pass='$reg_pass' "; $result = mysql_query($query); $num = mysql_num_rows($result); if (!$result) { echo "CRAP!"; } while ($row = mysql_fetch_array($result)) { echo $row['reg_firstname']; } print $query; $numrows = mysql_num_rows($result); print $numrows; ?> I looked at the database and all of the information is in there. Quote Link to comment Share on other sites More sharing options...
botlife Posted September 21, 2008 Author Share Posted September 21, 2008 Okay finally got it to work. Thanks for all of your help. Here is the corrected code. $reg_pass = $_POST['reg_pass']; $reg_email = $_POST['reg_email']; $query = " SELECT * FROM login WHERE reg_email='$reg_email' AND reg_pass='$reg_pass' "; $result = mysql_query($query) or die (mysql_error()); if (!$result) { echo mysql_error(); exit; } while($row = mysql_fetch_array($result) ) { echo $row['reg_firstname']; } Quote Link to comment 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.