Shoutbox

what is wrong with this php code..... - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: what is wrong with this php code..... (/showthread.php?tid=31716)

what is wrong with this php code..... by Eljay on 09-19-2004 at 03:06 PM

i dont actually get any errors
it just doesnt let me login

code:
<?
session_start();
if($_POST['submit'])
{
mysql_connect("localhost","****","****");
mysql_select_db("crimpa_forum");
$user = ($_POST['username']);
$pass = md5($_POST['password']);
$query = mysql_query("SELECT * FROM users WHERE username = '$user' AND password = '$pass' ");
$rows = mysql_num_rows($query);
      if($rows == 1)
      {
      echo 'user logged in successfully';
      $_SESSION['user'] = $user;
      $_SESSION['pword'] = md5($pword);     
      }
      else { echo 'incorrect username or password'; }
}
else
{
?>
<form method="post" action="login.php">
<TABLE>
<TR>
   <TD valign="top">Username:</TD>
   <TD><INPUT NAME='username' TYPE='TEXT' VALUE='' size=30 maxlength="30"></TD>
</TR>
<TR>
   <TD valign="top">Password</TD>
   <TD><INPUT NAME='password' TYPE='password' VALUE='' size=30 maxlength="16">
</TR><br>
   <TD valign="top"></TD>
   <TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>
<?
}
?>

RE: what is wrong with this php code..... by Choli on 09-19-2004 at 03:19 PM

quote:
Originally posted by leejeffery
$_SESSION['pword'] = md5($pword); 
I don't kno wmuch PHP, but shouldn't that line be $_SESSION['pword'] = $pass ?
RE: what is wrong with this php code..... by Eljay on 09-19-2004 at 03:26 PM

yeh ur right :P
still wont login mind ¬_¬


RE: what is wrong with this php code..... by Mnjul on 09-19-2004 at 03:55 PM

I suggest you do such debug:

1. echo the query ( "SELECT * FROM users WHERE username = '$user' AND password = '$pass' " ) to see if the query was executed correctly
2. echo $rows


RE: what is wrong with this php code..... by bach_m on 09-19-2004 at 04:19 PM

better than echo for an array: print_r


RE: what is wrong with this php code..... by Mnjul on 09-20-2004 at 12:48 PM

bach_m, his $rows is the number of the rows of the result of the query, not the rows themselves :P


RE: what is wrong with this php code..... by Eljay on 09-20-2004 at 03:10 PM

in case you didnt know, i was using this code because i was scripting my own forum but this login code just doesnt want to work and if people cant login then why bother. so i sort of gave up on making it :P
if anyone could get it to work i would continue :P