0

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

Michael
  • 503
  • 8
  • 18
  • 1
    can you run your php file through command line with `php myfile.php` and see if it displays anything? also add a couple more lines to error reporting `ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);` – Dimi Mar 27 '17 at 20:17

1 Answers1

1

You have to add name attribute to input tag

Replace

<input type="submit">

with

<input type="submit" name="submit">
Ravinder Reddy
  • 3,869
  • 1
  • 13
  • 22