PHP problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zura
Forum Newbie
Posts: 9
Joined: Mon Oct 17, 2011 1:04 am

PHP problems

Post by zura »

HI!
I have problem with this php scripts.
I write this script for check db. It works correctly but, checks only first login and password.
...thank you for help.

Code: Select all

<html>
<head>
</head>
<body>

<form method="post">
login:<input name="login" type="text" > <br /><br />
password:<input name="password" type="password" >  <br /><br />
<input type="submit" value="ok!" name="button">
</form>

<?php
$db = mysql_connect("localhost","user","");
mysql_select_db("dbname",$db);

$button=$_POST['button'];
if($_POST['button']==true){
 $login=$_POST['login'];
 $password=$_POST['password'];
 $query = "SELECT login, password FROM this";
	$result = mysql_query($query) or die (mysql_error());
	$res = mysql_fetch_array($result);
    if ($res[0] == $login){		
		if($res[1] == $password)  {echo "sucess";} /* or header */
		else{echo "incorrect password";}
	}
	else{echo "incorrect name";}
}
?>

</body>
</html>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP problems

Post by Celauran »

You haven't specified a WHERE clause for your query.

Code: Select all

SELECT somefield FROM tablename WHERE login = '$login' AND password = '$password';
Of course, before you pass $login and $password into your query, you're going to want to sanitize them.
Post Reply