php - Login page with mysql select where statment -
i have simple login page, on top simple form validations if , elseif statments. want write mysql select statement below validation code (elseif) statment. if email , password = email , password on database table record, redirect use secured page, , final (else) show error if email or password don't exist or match in database.
i don't know how right way, attempt doesn't work:
<?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php $email = $_post['email']; $hashed_password = md5($_post['password']); if (isset($_post['submit'])) { // form has been submitted. if ($_post['email'] == "") { $error = "email address required"; } elseif (!(filter_var($_post['email'], filter_validate_email))) { $error = "invalid email address"; } elseif ($_post['password'] == "") { $error = "type in password"; } elseif (strlen($_post['password']) < 8) { $error = "minimum password length 8"; } elseif { $query = "select id, email "; $query .= "from customers "; $query .= "where email = '{$email}' "; $query .= "and hashed_password = '{$hashed_password}' "; $query .= "limit 1"; $result_set = mysql_query($query); redirect_to("account.php"); } else { echo "error"; } } ?> <!-- signup box --> <div id="box_sign"> <div class="container"> <div class="span12 box_wrapper"> <div class="span12 box"> <div> <div class="head"> <h4>sign in</h4><br /> <div class="text-error"> <?php echo $error; ?><br /> <p class="text-success"><strong><?php echo $success; ?></strong></p> </div> </div> <div class="form"> <form action="sign-in.php" method="post"> <input type="text" id="email" name="email" placeholder="email"/> <input type="password" id="password" name="password" placeholder="password"/> <div class="right"> <a href="reset.html">forgot password?</a> </div> <input type="submit" name="submit" class="btn" value="sign in"/> </form> </div> </div> </div> <p class="already">don't have account? <a href="signin.html">sign up</a></p> </div> </div> </div>
redirect_to()
not pre-defined php function, it's custom function , you've picked code somewhere else , forgot pick function code.. should this
function redirect_to($link) { header('location: '.$link); exit; }
also elseif {
not valid, won't work without condition
Comments
Post a Comment