I am unable to enter data from HTML into a mysql table.

There are two files: an HTML file in which I made a form of three text fields and a submit button, and a php file for which I establish a connection to the database and through INSERT INTO I try to add a row in the table.

Here is the php code:

<?php echo "Hello World"; $connection = new mysqli('localhost' , 'root' ,'','accounts') or die("problem"); $valueFirst = $_POST['First']; $valueLast = $_POST['Last']; $valueKey = $_POST['Keywords']; $imsql = "INSERT INTO users (First,Last,Keywords) VALUES ('$valueFirst', '$valueLast', '$valueKey') "; echo "Hello 777"; ?> 

The connection works, but the data is not added.

How to make the machine understand from which fields to take data. How to link HTML-form with php-code?

If possible, write sample codes.

  • Examples, please, on mysqli. Thank you in advance) - vosxodnik
  • Show the HTML code. Well, as if where is the addition of data in the database? if ($ res = $ connection-> query ($ imsql)) {echo "OK"; $ connection-> close (); } - Mikhail Naletov

1 answer 1

Not the fact that you correctly send data from the form. But in general, should look something like this

 <?php echo "Hello World"; $connection = new mysqli('localhost' , 'root' ,'','accounts') or die("problem"); $valueFirst = $_POST['First']; $valueLast = $_POST['Last']; $valueKey = $_POST['Keywords']; $imsql = "INSERT INTO users (First,Last,Keywords) VALUES ('$valueFirst', '$valueLast', '$valueKey') "; if ($res = $connection->query($imsql)) { echo "OK"; }else{ printf("Error %s\n", $connection->error); } $connection->close(); ?>