Jump to content

[php][mysql]Problem with a session script

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
222333

222333

    Newbie

  • Members
  • Pip
  • 1 posts
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

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
$_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.