1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

It keeps saying signup=empty

Discussion in 'PHP' started by sarac93, Apr 22, 2018.

  1. #1
    This is the script. I can't figure out where the error is. Can you help me?
    I also posted the whole site in a zip file below.





    <?php
    if (isset($_POST['submit'])) {
     
        include_once 'dbh.inc.php';
     
        // Error handlers
        // Check for empty fields
        if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
            header("Location: ../signup.php?signup=empty");
            exit();
        } else {
                // Check if input characters are valid
                if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
                    header("Location: ../signup.php?signup=invalid");
                    exit();
                } else {
                    //Check if email is valid
                    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                        header("Location: ../signup.php?signup=email");
                        exit();
                    } else {
                        $sql = "SELECT * FROM users WHERE user_uid='$uid'";
                        $result = mysqli_query($conn, $sql);
                        $resultCheck = mysqli_num_rows($result);
                     
                        if ($resultCheck > 0) {
                            header("Location: ../signup.php?signup=usertaken");
                            exit();
                        } else {
                            //Hashing the password
                            $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
                            // Insert the user into the database
                            $sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd)
                            VALUES (?,?,?,?,?);";
                            mysqli_query($conn, $sql);
                            $stmt=mysqli_stmt_init ($conn);
                            if (!mysqli_stmt_prepare ($stmt, $sql)) {
                                echo "SQL error";
                             
                            } else {mysqli_stmt_bind_param ($stmt, "sssss", $first, $last, $email, $uid, $pwd);
                            mysqli_stmt_execute ($stmt);
                             
                            }
                            header("Location: ../signup.php?signup=success");
                            exit();
                        }
                    }
                }
        }
     
    } else {
        header("Location: ../signup.php");
        exit();
    }
    PHP:

    SEMrush
     

    Attached Files:

    Last edited by a moderator: Apr 22, 2018
    sarac93, Apr 22, 2018 IP
    SEMrush
  2. sarahk

    sarahk iTamer Staff

    Messages:
    24,239
    Likes Received:
    3,262
    Best Answers:
    92
    Trophy Points:
    615
    #2
    Hi

    is it as simple as you haven't extracted your variables? You don't show how $_POST['first'] gets to be $first

    if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
    PHP:
     
    sarahk, Apr 22, 2018 IP
  3. sarac93

    sarac93 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    you were right. thank you very much!
     
    sarac93, Apr 22, 2018 IP