URL is returned as www.website.com/undefined

228
July 24, 2017, at 7:17 PM

I am a bit new to programming and I am writing a prepared statement for my signup form. Part of the validation is to check and see if the email address already exists. The problem I am having is that the data is not being inserted, the code seems to stop working when i check if an email already exists and I am redirected to an undefined page I.E. www.mywebsite.com/undefined instead of profile.php. I am not getting any errors when check my log. I do not understand why it is doing this and if anyone can assist/teach me what I am doing wrong, it would be greatly appreciated. Mysqlnd is enabled and the API extensions are working. I checked my phpinfo() and the data is being sent and received.

signup.php

<?php
    session_start();
    include '../dbh.php';
    $respond = array(
        'status' => true,
        'message' => 'There was an error',
        'redirect',
        'errors'
    );
    if (isset($_POST['submit'])) {
        $first = $_POST['first'];
        $last  = $_POST['last'];
        $email = $_POST['email'];
        $pwd   = $_POST['pwd'];
        $errorEmpty = false;
        $errorEmail = false;

        if (empty($first) || empty($last) || empty($email) || empty($pwd)) {
            $respond['errors'][]   = "Please fill out all fields!";
            $respond['errorEmpty'] = true;
        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $respond['errors'][]   = "Please enter a valid email address!";
            $respond['errorEmail'] = true;
        } else {
            $sql  = "SELECT email FROM user WHERE email= ? ";
            $stmt = mysqli_prepare($conn, $sql);
            mysqli_stmt_bind_param($stmt, 's', $email);
            mysqli_stmt_execute($stmt);
            $result   = mysqli_stmt_get_result($stmt);
            $num_rows = mysqli_num_rows($result);
            if ($num_rows > 0) {
                $respond['errors'][]   = "That email address already exists!";
                $respond['errorEmail'] = true;
            }
            else {
                $encryptpwd = password_hash($pwd, PASSWORD_DEFAULT);
                $sql        = "INSERT INTO user (first, last, email, pwd) VALUES (?,?,?,?)";
                $stmt       = mysqli_prepare($conn, $sql);
                mysqli_stmt_bind_param($stmt, 'ssss', $first, $last, $email, $password_hash);
                if (mysqli_stmt_execute($stmt)) {
                    $userID = mysqli_insert_id($conn);
                    $status = 1;
                    $sql2   = "INSERT INTO profileImg (email, status) VALUES(?,?)";
                    $stmt2  = mysqli_prepare($conn, $sql2);
                    mysqli_stmt_bind_param($stmt2, 'si', $email);
                    mysqli_stmt_execute($stmt);
                    $_SESSION['id'] = $userID;
                    $respond['redirect'] = "../profile.php?id=$userID"; // redirect to the actual ID of the user who just signed up
                }
            }
        }
    }
    echo json_encode($respond);
    ?>

profile.php

<?php
session_start();
include 'dbh.php';
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Yahbang</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header class="header_profile">
    <nav>
        <ul>
        </ul>
    </nav>
    <form class="logout" action='include/logout.inc.php'>
        <button>Log out</button>
        </form>
</header>
<?php
    $sql = "SELECT * FROM user";
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
        $id = $row['id'];
        $sqlImg = "SELECT * FROM profileImg WHERE id='$id'";
        $resultImg = mysqli_query($conn, $sqlImg);
        while ($rowImg = mysqli_fetch_assoc($resultImg)) {
            echo "<div class='userProfileImage'>";               
                if ($rowImg['status'] == 0 ) {
                    echo "<img src='images/profile".$id.".jpg'>";
                } else {
                    echo "<img src='images/profile_default.jpg'>";
                }
                echo "<p>".$row['first']."</p>";
            echo "</div>";
        }
    }   
}       else {
            echo "There are no users yet!";
        }

    if (isset($_SESSION['id'])) {
        echo "<form action='include/uploadProfile.inc.php' method='POST' enctype='multipart/form-data'>
<input type='file' name='file'>
<button type='submit' name='submit'>UPLOAD</button>
    </form>";
    } else {
        header("Location: ../index.php");
        exit();
    }
?>



<footer class="footer_profile">
    <nav>
        <ul>
        </ul>
    </nav>
</footer>
</body>
</html>
Rent Charter Buses Company
READ ALSO
mysqli prepared statement order by

mysqli prepared statement order by

I have a friendship table called friends that looks like this:

300
Why am I getting the &ldquo;Class &#39;Artisan&#39; not found&rdquo; error?

Why am I getting the “Class 'Artisan' not found” error?

I am currently using artisan with laravel and I get the following error if I try to run any command with artisan (such as php artisan optimize):

206
Read JSON Multipart request in php

Read JSON Multipart request in php

Android is sending data to server in JSON formatIt includes image files in request

385
Eloquent/PHP range (from/to)

Eloquent/PHP range (from/to)

For example, my database structure is:

257