mysql - PHP returns multiple strings -
mysql - PHP returns multiple strings -
i'm trying build login page forums using apache , mysql xampp databases, returns echo string multiple times, know goes through of rows in database checking if it's true or not returns "invalid username or password!" until finds right login info returns "welcome" might be.
while($rows = mysql_fetch_row($result)) { //echo $rows; if($name==$rows[1]) { if($pass==$rows[2]) { echo "welcome!"; } } else if ($name!==$rows[1]) { echo "invalid username or password!"; if($pass!==$rows[2]) { echo "invalid username or password!"; } } $row = $row + 1; } here output:
invalid username or password!invalid username or password!invalid username or password!invalid username or password!welcome!
how done returns 1 wrong , right strings?.
i'm going different perspective. first of mysql_* extension deprecated in of php 5.5.0 , it's utilize discouraged.
the next thing think you're going wrong way this. why loop through entire table credentials when can check if there record username , password? highly inefficient.
class="lang-php prettyprint-override">$stmt = $mysqli->prepare("select * users username = ? && password = ?"); $stmt->bind_param("ss", $name, $pass); $stmt->execute(); $stmt->store_result(); $stmt->close(); // found record username , password match if ($stmt->num_rows > 0) { echo 'welcome!'; // no records either username or password doesn't match } else { echo 'invalid username or password!'; } php mysql loops while-loop
Comments
Post a Comment