Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <div class="form-group">
- <label for="exampleInputUsername">Username</label>
- <input type="text" name="name" class="form-control" id="exampleInputUsername" placeholder="enter username">
- <span class="error_message"><?php echo $nameErr;?></span>
- </div>
- <div class="form-group">
- <label for="exampleInputEmail1">Email address</label>
- <input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
- <span class="error_message"><?php echo $emailErr;?></span>
- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
- </div>
- <button type="submit" name="signupBtn" class="btn btn-primary">SIGNUP</button>
- </html>
- <?php
- if(isset($_POST['signupBtn'])){
- $name = trim($_POST['name']);
- $email = trim($_POST['email']);
- $hashed_password = password_hash($pwd, PASSWORD_DEFAULT);
- $encrypted = password_hash($cpwd, PASSWORD_DEFAULT);
- // check if user already exist
- $username_exist = "SELECT * FROM signup WHERE username=:name";
- $email_exist = "SELECT * FROM signup WHERE email=':email'"; // check your syntax, find the difference compare your last statement above
- $username_result = $dbh->prepare($username_exist);
- $email_result = $dbh->prepare($email_exist);
- $username_result->bindParam(':name', $name);
- $email_result->bindParam(':email', $email);
- $username_result->execute(); // why $username_result->execute() twice?
- if($username_result->execute() && $username_result->rowCount() > 0){
- return true;
- } elseif ($email_result->execute() && $email_result->rowCount() > 0) {
- return true;
- } else { // what happen if $username_result->execute() or $username_result->execute() return false?
- // insert into database
- $insert="INSERT INTO signup(username, email, password, confirm_password) VALUES(:name, :email, :pwd, :cpwd)";
- // why you need to store confirmed password to table?
- $statement = $dbh->prepare($insert);
- $statement->bindParam(':name', $name);
- $statement->bindParam(':email', $email);
- $statement->bindParam(':pwd', $hashed_password);
- $statement->bindParam(':cpwd', $encrypted);
- if ($statement->execute() && $statement->rowCount() > 0) {
- $result = "row inserted";
- }else {
- $result = "insertion failed";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement