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; } ?>
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