The Saint Posted August 4, 2007 Share Posted August 4, 2007 hey this will be easy for alot of experts to help me so when i made a basic login form and filled it out i say this Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp2\www\Saintsprojects\do_login.php on line 12 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp2\www\Saintsprojects\do_login.php:12) in C:\wamp2\www\Saintsprojects\do_login.php on line 25 [/b] ALso id like to elaborate a little more i followed a php tutorial, everythings good, i put in my name and pass and thats what i got Link to comment https://forums.phpfreaks.com/topic/63324-solved-login-help/ Share on other sites More sharing options...
dbo Posted August 4, 2007 Share Posted August 4, 2007 You've got to post some applicable code buddy. Regardless if you followed a tutorial... online tutorials aren't always correct. The second error is likely caused by the first... so fix it before worrying about error 2. Link to comment https://forums.phpfreaks.com/topic/63324-solved-login-help/#findComment-315567 Share on other sites More sharing options...
The Saint Posted August 4, 2007 Author Share Posted August 4, 2007 DO_LOGIN.PHP <?php $connection = mysql_connect(localhost,prefix_user,""); $db = mysql_select_db(prefix_dbname,$connection); $sql = "SELECT id FROM user WHERE username='$_POST[username]' And password='$_POST[password]'"; $result = mysql_query($sql); $num - mysql_num_rows($result); if ($num > 0) { //USERNAME AND PASS ARE CORRECT $id = mysql_fecth_assoc($result); setcookie("auth", "yes", time()+3600); setcookie("id", $id['id']); setcookie("username", $id['username']); header("Location: main.php"); }else { header ("Location: incorrect.php"); }; ?> ________________________________________________________________________________ LOGIN.PHP <body background="blue.jpg"> <font face="arial"> <form name=login action=do_login.php method=post> <table border=0 cellspacing=0 cellpadding=2> <tr><td> Username:<td><input type=text name=username> <tr><td> Password:<td><input type=password name=password> <tr><td colspan=2 align=left> <img src="blue.jpg"height="2" width="59"><input type=submit value='Login'><form method="GET" action="refreshbutton.htm" align=right><input type="button" onclick="refresh()" value="Reload Pass" name="button1"><br><input type="checkbox" name="remember"> <font size="2">Remember me next time</td></tr></p> </table> </form> </body> </html> <html> <head> <script language="JavaScript"> --> <!-- /. var sURL = unescape(window.location.pathname); function refresh() { window.location.href = sURL; } //--> </script> <script language="JavaScript1.1"> <!-- function refresh() { window.location.replace( sURL ); } //--> </script> <script language="JavaScript1.2"> <!-- function refresh() { window.location.reload( false ); } //--> </script> </head> <body> <!-- </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/63324-solved-login-help/#findComment-315580 Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 First, I always put an or die() after a mysql_query, like so: $result = mysql_query($sql) or die(mysql_error()." -- $sql"); This will die with the MySQL error and the sql statement that caused it. Now, looking at your SQL, I see two quoted $_POSTs, which is probably what's messing it up, or at very least it won't give you the result you expect. Try this instead: $sql = "SELECT id FROM user WHERE username='".$_POST[username]."' And password='".$_POST[password]."'"; -BSIS Link to comment https://forums.phpfreaks.com/topic/63324-solved-login-help/#findComment-315712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.