<? $db_host = 'localhost'; $db_name = 'figures'; $db_username = 'root'; $connect_to_db = mysql_connect($db_host, $db_username, $db_password) or die("Не найдено соединение: " . mysql_error()); mysql_select_db($db_name, $connect_to_db) or die("Не найдена бд: " . mysql_error()); ?> 

Here is a screen DB

  <!doctype html> <html> <head> <meta charset="utf-8"> <title>Документ без названия</title> </head> <body> <form method="post" action="add.php"> <input type="text" name="obj"> <input type="text" name="stl"> <input type="text" name="aboutStl"> <input type="text" name="aboutObj"> <input type="submit" name="add" value="Добавить"> </form> <? include('set.php'); if(isset($_POST['add'])) { $obj = $_POST ['obj']; $stl = $_POST ['stl']; $aboutObj = $_POST ['aboutObj']; $aboutStl = $_POST ['aboutStl']; mysql_query("INSERT INTO figures(obj, stl, aboutObj, aboutStl) VALUES ('$obj','$stl,'$aboutObj','$aboutStl')"); mysql_close; } ?> </body> </html> 
  • and then there is the code?))) seems to be like if not closed}, and the form Not closed! BRING the full code, from this sheet you can see at least two formatting errors so far - Sergey V.
  • Maybe </ form> not closed? - iKey
  • And what, actually gives an error? - Klym Nov.
  • @Denis there everything is closed below, just inserted without unnecessary tags - Michael
  • @Klym does not issue, just does not write to the database - Michael

1 answer 1

You have an error in the request, you incorrectly use quotes.

Try this:

 mysql_query(' INSERT INTO figures (`obj`, `stl`, `aboutObj`, `aboutStl`) VALUES ("' . $obj . '", "' . $stl . '", "' . $aboutObj . '", "' . $aboutStl . '") '); 

Or this way (I never used it this way, but in theory it should work too) :

 mysql_query(" INSERT INTO figures (`obj`, `stl`, `aboutObj`, `aboutStl`) VALUES ('$obj', '$stl', '$aboutObj', '$aboutStl) "); 

To find out the reasons, try to find out what the error is:

 $result = mysql_query(' INSERT INTO figures (`obj`, `stl`, `aboutObj`, `aboutStl`) VALUES ("' . $obj . '", "' . $stl . '", "' . $aboutObj . '", "' . $aboutStl . '") '); if (!$result) { die('Неверный запрос: ' . mysql_error()); } 

And on the screen of the database structure you have a gap in the last two columns - get rid of it =)

PS You have an ideal injection code, use PDO and prepared queries :)

  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin
  • @ Nikolay, you yourself made a mistake without putting the variables in quotes .... I corrected, but ..... oh ..... - Alexey Shimansky