matt_jo84 Posted March 13, 2007 Share Posted March 13, 2007 I have been having some problems with a part of my login script. This is the two lines of script I am having problems with: mysql_query("UPDATE " . $userName. " SET login = '$loginIN' WHERE pass = '$password' AND course = '$courseID'"); header( 'url=http://www.somewebsite.com/logged_IN.htm' ); The problem is that when this php script is executed the second line executes before the first and an update to the database is not made. I also tried the script without the second line and the first works then. If anyone could help me out with this problem I would really appreciate it. Quote Link to comment Share on other sites More sharing options...
Lumio Posted March 13, 2007 Share Posted March 13, 2007 what is url= ? It has to be header('Location: www.someonesweb.com'); Quote Link to comment Share on other sites More sharing options...
matt_jo84 Posted March 13, 2007 Author Share Posted March 13, 2007 Both methods seem to work, I tried it with 'Location: ' also and the script still doesn't work right. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 13, 2007 Share Posted March 13, 2007 You really should make sure the query is done before you execute the header() function: <?php $q = "UPDATE " . $userName. " SET login = '$loginIN' WHERE pass = '$password' AND course = '$courseID'"; $rs = mysql_query($q) or die("There was a problem with the query <pre>$q</pre><br>" . mysql_error()); header( 'url=http://www.somewebsite.com/logged_IN.htm' ); ?> Ken Quote Link to comment Share on other sites More sharing options...
matt_jo84 Posted March 13, 2007 Author Share Posted March 13, 2007 I tried that code, but once again it still does not update on the database. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 13, 2007 Share Posted March 13, 2007 For debugging purposes, change the header() line to: <?php exit("The number of rows affected by the query <pre>$q</pre> was " . mysql_affected_rows($rs)); ?> If this reports that zero rows were affected, check your query to make sure it is logically correct. Ken Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 13, 2007 Share Posted March 13, 2007 The problem is that when this php script is executed the second line executes before the first and an update to the database is not made. Unless you've found an obscure bug within PHP, which I doubt, this is entirely impossible. Code executes sequentially. The interpretor doesn't arbitrarily decide to execute some lines, skip others, or randomly jump from location to location. The reason I bring this up is that you seem to think you're doing everything correct and that PHP is the cause of the error. The posts before mine are giving you advice on how to find the error that you made. Slightly less than 100% of the time your code is not working, it's a mistake the programmer made. Keep that in mind and your life will be much easier in terms of debugging. Quote Link to comment Share on other sites More sharing options...
matt_jo84 Posted March 13, 2007 Author Share Posted March 13, 2007 Hello roopurt18, I completely understand what you are saying, i'm am not assuming php is at fault which is the reason I am attempting to use a forum to see if I am in fact doing something wrong. I understand that code executes sequentially. I am simple telling you what I am experiencing, no assumptions are being made about PHP itself or that I am doing everything right because I am not an by any means an expert with PHP. As for kenrbnsn: I tried what you said and I get this "Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource", and then nothing in printed out for "mysql_affected_rows($rs)", but the right variables for update are shown and the correct update to the database is made since the header function was removed. 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.