Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isset($_POST['submit'])){
- include_once 'dbh.inc.php';
- $username = mysqli_real_escape_string($conn, $_POST['username']);
- $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
- $email = mysqli_real_escape_string($conn, $_POST['email']);
- if(empty($username) || empty($pwd) || empty($email)){
- echo "Fill in all Fields!";
- }else {
- if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
- echo "Email is invalid!";
- }else{
- $stmt = $conn->prepare("SELECT * FROM users WHERE username=?");
- $stmt->bind_param("s", $uid);
- $uid = $username;
- $stmt->execute();
- $result = $stmt->get_result();
- $usernamecheck = mysqli_num_rows($result);
- $rowNum = $result->num_rows;
- if($rowNum > 0){
- echo "Username is taken!";
- }else{
- $stmt = $conn->prepare("SELECT * FROM users WHERE email=?");
- $stmt->bind_param("s", $uemail);
- $uemail = $email;
- $stmt->execute();
- $result = $stmt->get_result();
- $usernamecheck = mysqli_num_rows($result);
- $rowNum = $result->num_rows;
- if($rowNum > 0){
- echo "Email is taken";
- }else{
- $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
- $stmt = $conn->prepare("INSERT INTO users (username, pwd, email) VALUES (?, ?, ?)");
- $stmt->bind_param("sss",$uid, $password, $theemail);
- $uid = $username;
- $password = $hashedPwd;
- $theemail= $email;
- $stmt->execute();
- $result = $stmt->get_result();
- header("location: ../user-login.php");
- }
- }
- }
- }
- }else{
- header("location: ../user-signup.php");
- exit();
- }
- include_once '../dbh.inc.php';
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $username = $_POST['username'];
- $email = $_POST['email'];
- $pwd = $_POST['pwd'];
- if(empty($username) || empty($pwd) || empty($email)){
- echo "Fill in all Fields!";
- exit();
- }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
- echo "Email is invalid!";
- exit();
- }else{
- $chk = "SELECT * FROM user WHERE email='$email'";
- $result = mysqli_query($conn, $chk);
- while ($row = mysqli_fetch_array($result)) {
- if ($row['email'] == $email) {
- echo "Email Match";
- exit();
- } else {
- $chk = "SELECT * FROM user WHERE username='$username'";
- $result = mysqli_query($conn, $chk);
- while ($row = mysqli_fetch_array($result)) {
- if ($row['username'] == $username) {
- echo "Username Match";
- exit();
- } else {
- $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
- $join = sprintf("INSERT INTO user(username, email, password) " .
- "VALUES ('%s', '%s', '%s', '%s'); ",
- mysqli_real_escape_string($conn, $username),
- mysqli_real_escape_string($conn, $email),
- mysqli_real_escape_string($conn, $hashedPwd),
- mysqli_insert_id($conn));
- if (mysqli_query($conn, $join)) {
- $i = "joined";
- } else {
- $i = "failed to join";
- }
- echo $i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement