php - How to check username and password match -
i'm trying check if users entered username , password matches entry database using pdo, reason cannot seem working.
the database table called user_info , rows i'm trying grab username , password username , pass respectively. i'm not exclusively sure how check if users input info matches database entry, create decision on send them based on if returns true or false.
also, i've got prerequisites such including file connects database, know info correct.
i've had stab in dark on if ($username) etc, it's incorrect.
html
<form method="post"> <label for="username2">username</label> <input type="text" name="username"> <label for="password">password</label> <input type="text" name="password"> <input type="submit" value="login" name="login"> </form> php
$username = $_post['username']; $password = $_post['password']; seek { $result = $db->prepare("select * user_info username = :user , pass = :pass"); $result->bindparam(':user', $username); $result->bindparam(':pass', $password); $result->execute(); $rows = $result->fetch(pdo::fetch_num); } grab (exception $e) { echo "could not retrieve info database"; exit(); } if ($username == "test" && $password == "test") { $_session['username'] = $username; redirect('/add-property.php'); } else { if (isset($_post['login'])) { echo "username or password incorrect"; } }
what can user in database , homecoming row query. after compare password given user authenticate , 1 query returned homecoming them need go.
php mysql database pdo
No comments:
Post a Comment