Hello! There was a problem in adding this to mysql. The form is filled, but when you click on the button, nothing is added to the database, and the data from the form does not even go to the add.php file. Help me find problems.

Код html <html> <head> <title>HTML-форма добавления новых книг</title> </head> <body> <form name="forma" aсtion="add.php" method="post"> <input type="text" name="i" /><br> <input type="text" name="f" /><br> <input type="text" name="n" /><br> <input type="text" name="o"/><br> <input type="submit" value="Ввод"/> </form> </body> </html> код php <html> <head> <title>Программа добавления новых книг (файл insert_book.php)</title> </head> <body> <?php $i=$_POST['i']; $f=$_POST['f']; $n=$_POST['n']; $o=$_POST['o']; $link = mysql_pconnect("localhost","root","") or die ("Невозможно подключение к MySQL"); mysql_select_db("dog") or die ("Невозможно открыть таблицу с данными"); $query = ("INSERT INTO prepod (idprepoda, familiya, name, otchestvo) VALUES ('$i', '$f', '$n', '$o')"); mysql_query ( $query ); if ($query == 'true') echo "Добавлено в базу данных."; mysql_close ($link); ?> </body> </html> 
  • when instead of variables here VALUES ('$ i', '$ f', '$ n', '$ o'), you write like this VALUES ('1', 'Ivanov', 'Ivan', 'Ivanovich') then record is added - ivan9095
  • depricated This extension is deprecated since PHP 5.5.0 and will be removed in the future. Use MySQLi or PDO_MySQL instead. See also the MySQL instruction: API selection and the corresponding FAQ for more details. Alternatives to this function: mysqli_connect () PDO :: __ construct () - zb '18
  • And for some reason, when you add Russian words to the database, then in the database instead of words exclamation marks, how can I fix this? in comparison is worth cp1251_bin - ivan9095
  • one
    are you on a time machine from the late 90s? - zb '
  • After pressing the enter button, the data is not sent to the php file, but it turns out that the page is being updated and just the forms are reset and that's it. php file does not open - ivan9095

1 answer 1

Try this:

 $query = ("INSERT INTO prepod (idprepoda, familiya, name, otchestvo) VALUES ('".$i."', '".$f."', '".$n."', '".$o."')"); 

In general, go to PDO .

  • but show an example of PDO or a link with an example, please throw - ivan9095
  • Yes, the problem is that in single quotes the variable will not be processed) - IVsevolod
  • @ ivan9095> and show an example of a PDO or an example link, please drop the first link in Google to the request [PDO] [1] [1]: php.net/manual/ru/book/p.pdo.php - abibock_un
  • @ ivan9095, Start learning PDO with this [review article] [1]. Understand the principle, and further to the manuals, the link to which you gave above @abibock_un [1]: Why you should use PDO - Deonis