mysql - PHP Only Selecting First Row? -
i have quick login form made school problem when try , login worked when want log first user (username: hbutler password: password) when try login other accounts page refresh have set if incorrect here code :
<?php //create connection… //("where database is", 'database login' , 'database password' , "database name") $con=mysqli_connect("", 'root', 'root', "social"); //check our connection… if (mysqli_connect_errno($con)) { echo " sorry mate"; } $username = $_post['username']; $password = $_post['pawd']; $result = mysqli_query($con, "select * user_info"); $row = mysqli_fetch_array($result); $value = $row['username']; if($value == "$username") { $result = mysqli_query($con, "select * user_info username ='$username'"); $row = mysqli_fetch_array($result); $value = $row['password']; if($value == "$password") { $sql=("update user_check set user = '1', name = '$username'"); header( 'location: feed.php' ) ; } else { header( 'location: social.php' ) ; } } else { header( 'location: social.php' ) ; } if (!mysqli_query($con,$sql)) { die('error: ' . mysqli_error($con)); } mysqli_close($con); ?>
which gets form data previous page not know why happening , have tryed changing php :
$result = mysqli_query($con, "select username user_info"); $row = mysqli_fetch_array($result); if($row == "$username")
yet doesnt work either suggestions?
the problem that, after first query, info db, taking first row of table,
$row = mysqli_fetch_array($result);
then comparing submitted username, that's why can't login other username, solution add clause first query,
$result = mysqli_query($con, "select * user_info username ='".$username."'");
then compare passwords easier, still, there better ways authentication. example should do.
Comments
Post a Comment