What did you do wrong? And how to make that id that will match will not be added?

<!DOCTYPE html> <html> <head> <title>My page</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="main"> <?php include("header.php"); ?> <?php include ("menu.php"); ?> <div class=magazin> <form action="admin.php" method="post"> ID<br> <input type="numeral" name="id"><br> Name<br> <input type="text" name="name"><br> Price<br> <input type="numeral" name="price"><br> Description<br> <input type="text" name="description"><br> Src<br> <input type="text" name="src"><br> <input type="submit" name="insert"> </form> <?php $link=mysqli_connect("localhost","root","usbw","litle"); if ($_POST["insert"]) { $id=($_POST['id']); $name=($_POST['name']); $price=($_POST['price']); $description=($_POST['description']); $src=($_POST['src']); $sql=" INSERT INTO `products` (`id`,`name`,`price`,`description`,`src`) VALUES ('$id,'$name','$price','$description','$src')"; mysqli_query($link,$sql); echo "Тавар успешно дабавлень"; mysqli_close($link); } ?> <?php include("footer.php"); ?> </body> </html> 

    1 answer 1

    The id field in your database should be PRIMARY_KEY and AUTO_INCREMENT and be created automatically. id is not written to the database manually.

    Your code should be:

     <?php if ($_POST["insert"]) { $link = new Mysqli("localhost","root","usbw","litle"); $name = $_POST['name']; $price = $_POST['price']; $description = $_POST['description']; $src = $_POST['src']; $sql = " INSERT INTO `products` (`name`,`price`,`description`,`src`) VALUES ('$name','$price','$description','$src')"; if($link->query($sql)) { echo "Тавар успешно дабавлень"; } } ?> <!DOCTYPE html> <html> <head> <title>My page</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="main"> <?php include("header.php"); ?> <?php include ("menu.php"); ?> <div class=magazin> <form action="admin.php" method="post"> Name<br> <input type="text" name="name"><br> Price<br> <input type="numeral" name="price"><br> Description<br> <input type="text" name="description"><br> Src<br> <input type="text" name="src"><br> <input type="submit" name="insert"> </form> </div> </div> </body> </html> 
    • Instead of an id, I’ve been singing a null automamatic And how can I use the ID and so that they don’t fall off - Hrayr Khachatryan