Garloz Posted April 1, 2010 Share Posted April 1, 2010 Hi, sorry for disturbing. I have tried some ways, but I can't figure it out. I have the following code in my PHP file. It does'nt take(check) username and password from database.. But I want that it will do. I copied it from another website, so.. it's not my code. But I need it Something musst be wrong on this.. $query = "SELECT id FROM testtable WHERE (username='$lo' AND password=password('$pa') )"; $result = @mysql_query ($query); $num = mysql_num_rows ($result); if ($num == 1) { $row = mysql_fetch_array($result, mysql_NUM); // Make the query. $query = "UPDATE testtable SET password=password('$npa') WHERE id=$row[0]"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. echo '<p><b>Your password has been changed.</b></p>'; Quote Link to comment https://forums.phpfreaks.com/topic/197243-cant-check-from-database-and-update/ Share on other sites More sharing options...
fenway Posted April 3, 2010 Share Posted April 3, 2010 Well, start debugging -- figure out which part isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/197243-cant-check-from-database-and-update/#findComment-1036441 Share on other sites More sharing options...
havenpets Posted April 3, 2010 Share Posted April 3, 2010 Try this... $query = "SELECT * FROM testtable WHERE username='$lo' AND password=password('$pa')"; $result = @mysql_query ($query); $num = mysql_num_rows ($result); if ($num == 1) { $row = mysql_fetch_object($result); // Make the query. $query = "UPDATE testtable SET password=password('$npa') WHERE id='$row->id'"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. echo '<p><b>Your password has been changed.</b></p>'; Don't be too sure about my response... I can Quote Link to comment https://forums.phpfreaks.com/topic/197243-cant-check-from-database-and-update/#findComment-1036466 Share on other sites More sharing options...
havenpets Posted April 3, 2010 Share Posted April 3, 2010 I can't really understand why it wouldn't be working. Try doing mysql_query($query) or die(mysql_error()); As a debugging tool. Quote Link to comment https://forums.phpfreaks.com/topic/197243-cant-check-from-database-and-update/#findComment-1036470 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.