Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[php][mysql]Problem with a session script

mysql session

  • Please log in to reply
1 reply to this topic

#1 222333

222333

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 30 December 2007 - 01:00 AM

My script works on sessions. It connects to MySQL Database and chooses a password. Something is wrong, because it doesn't work - it always shows "Pass or login wrong".

<form action="index.php" method="post"><input type="text" name="login" /><br />
<input type="text" name="pass" /><input type="submit" value="send" /></form>
<?php

$conn=mysql_connect("localhost", "root", "krasnal");
mysql_select_db("pass");
$choose="SELECT `cpass` FROM `pass`";
$r = mysql_query($choose);
$wynik = mysql_fetch_array($r);

if(!empty($_POST['login']) && !empty($_POST['pass']))
{
if($_POST['login']=='login' && $_POST['pass']==$choose['cpass'])
{
$_SESSION['logged']=$_POST['login'];
echo 'logged';
}
else
{
echo 'Pass or login wrong!!!';
}

}


mysql_close($conn);

?>

please help
  • 0

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 30 December 2007 - 11:07 AM

$_POST['pass']==$choose['cpass']


$choose is the query, not the result. $wynik is your result. Even so
$_POST['pass']==$wynik['cpass']

will still return false because $wynik['cpass'] is an array of strings, not a single string, which you are checking for. You can get it to work using a loop or one of the array functions, but in general this is a poor login script.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download