jeudi 9 novembre 2017

Cannot POST /insertUser.php

I want to insert user to my database but I get error message in my browser page. I open mysql workbench and server is online. Is there anything wrong in my code?

php

$conn = mysql_connect( "localhost", "root", "123456");

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

    $dbselect = mysql_select_db("inputdatabase");
    $username = $_POST['username'];
    $password = $_POST['password'];

    $sql = "INSERT INTO studenttable (nickname, password) VALUES ('$username', '$password')";
    $loginpage = 'C:/website/loginPage.html';
    $index = 'C:/website/index.hmtl';
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
        header( "Location: $index" );
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
        header( "Location: $loginpage" );
    }

$conn->close();
}
?>

html

      <form action="insertUser.php" method="post">    
          <div class="containerLogin">
            <label><b>Username</b></label>
            <input type="text" placeholder="Enter Username" name="username" required>
            <label><b>Password</b></label>
            <input type="password" placeholder="Enter Password" name="password" required>
                <button type="submit">Login</button>
            <input type="checkbox" checked="checked"> Remember me
          </div>
          <div class="containerLogin" style="background-color:#f1f1f1">
            <button type="buttonLogin" class="cancelbtn">Cancel</button>
            <span class="password">Forgot <a href="#">password?</a></span>
          </div>
        </form>




Aucun commentaire:

Enregistrer un commentaire