lundi 27 mars 2017

beginner php mysql - insert data to table from input form

im trying to add data to my database, and this data come from an html form.

here's my code:

<?php

error_reporting(E_ALL);

$conn = new mysqli(/* private info's */);

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

if(isset($_POST['submit'])) {

    $getName = $_POST['name'];

    $query = "INSERT INTO data ('name') VALUES ($getName)";

    if ($conn->query($query) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $query . "<br>" . $conn->error;
    }

    $conn->close();
}
?>

<html>

<form method="post">
    Name: <input type="text" name="name"><br>
    <input type="submit">
</form>

</html>

I don't know why but when I click on the button, absolutely nothing happen.

Thanks for any help




Aucun commentaire:

Enregistrer un commentaire