Hello, please help me figure out where the error is. I check through terminal SELECT * FROM catalog; The table is empty.

config.inc.php

 <?php define ("DB_HOST", "localhost"); define ("DB_LOGIN", "root"); define ("DB_PASSWORD", "root"); define ("DB_NAME", "eshop"); define ("ORDERS_LOG", "orders.log"); $basket = array(); $count = 0; $link = mysqli_connect( DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME ) or die(mysqli_connect_error()); ?> 

lib.inc.php

 <?php function addItemToCatalog($title, $author, $pubyear, $price) { global $link; $sql = "INSERT INTO catalog (title, author, pubyear, price) VALUES (?, ?, ?, ?)"; if (!$stmt = mysqli_prepare($link, $sql)) { return false; } mysqli_stmt_bind_param($stmt, "ssii", $title, $author, $pubyear, $price); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); return true; } function filter($str, $type="s") { switch ($type) { case "s": return mysqli_real_escape_string(trim(strip_tags($str))); break; case "i": return (int)$str; break; } } 

add2cat.php

 <? require "secure/session.inc.php"; ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Π€ΠΎΡ€ΠΌΠ° добавлСния Ρ‚ΠΎΠ²Π°Ρ€Π° Π² ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³</title> </head> <body> <form action="save2cat.php" method="post"> <p>НазваниС: <input type="text" name="title" size="100"> <p>Автор: <input type="text" name="author" size="50"> <p>Π“ΠΎΠ΄ издания: <input type="text" name="pubyear" size="4"> <p>Π¦Π΅Π½Π°: <input type="text" name="price" size="6"> Ρ€ΡƒΠ±. <p><input type="submit" value="Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ"> </form> </body> </html> 

save2cat.php

 <?php // ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊ require "secure/session.inc.php"; require "../inc/lib.inc.php"; require "../inc/config.inc.php"; $title = filter($_POST["title"]); $author = filter($_POST["author"]); $pubyear = filter($_POST["pubyear"]); $price = filter($_POST["price"]); if (!addItemToCatalog($title, $author, $pubyear, $price)) { echo "ΠŸΡ€ΠΎΠΈΠ·ΠΎΡˆΠ»Π° ошибка"; } else { header("Location: add2cat.php"); exit; } ?> 
  • Add the following code to the beginning of the save2cat.php file and provide the error text ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); - Artem Y
  • @Rikaz Warning: mysqli_real_escape_string () expects exactly 2 parameters, 1 given in /Applications/MAMP/htdocs/PHP/files/eshop/inc/lib.inc.php on line 18 Warning: mysqli_real_escape_string () uses 2 exactly, 1 given in /Applications/MAMP/htdocs/PHP/files/eshop/inc/lib.inc.php on line 18 Warning: Cannot modify header information / PHP / htdocs / PHP / files / eshop / inc / lib.inc.php: 18) in /Applications/MAMP/htdocs/php/files/eshop/admin/save2cat.php on line 16 - Jas Hakimov
  • @rikaz Found a mistake) Thank you very much - Jas Hakimov 4:39 pm
  • Always happy to help) - Artem Y
  • By the way, why do I need real_escape_string. you use the binding of the penny, it means no shielding of the lines during transmission is required - Mike

0