简体   繁体   中英

html form updating with php

I am trying to update my phpmyadmin database using the php and html code below: I have been successful in adding a first row of data, but once I try to use the form again I cannot add another row of data unless I delete the previous one I inserted into the database. In short, I can only have 1 row in my database at a time. Thanks for any help :)

<html>
<head>
</head>
<body>

    <form action="inserto.php" method="post">

        Customer ID: <input type="number" name="IDc">
            <br/>
        Stock ID: <input type="number" name="IDs">
            <br/>
        Date of Purchase: <input type="date" name="dob">
            <br/>
        Pay status: <input type="text" name="paystatus">
            <br/>
        Price Paid: <input type="text" name="price">
            <br/>
        Discount: <input type="text" name="discount">
            <br/>
        <input type="submit" value="Submit">
    </form>






</body>
</html>


<?php

    $con = mysqli_connect("localhost", "root", "", "jainam_ia");

    if(!$con)
    {
        echo 'Not connected';
    }

    $IDc=$_POST['IDc'];
    $IDs=$_POST['IDs'];
    $dob=$_POST['dob'];
    $paystatus=$_POST['paystatus'];
    $price=$_POST['price'];
    $discount=$_POST['discount'];

    $sql = "INSERT INTO tbl_orders (IDc, IDs, Date_of_purchase, Pay_Status, Price_Paid, Discount) VALUES ('$IDc', '$IDs', '$dob', '$paystatus', '$price', '$discount')";

    if(!mysqli_query($con,$sql))
    {
        echo 'Order not added';
    }
    else
    {
        echo 'Order added';
    }

    header("refresh:2; url=indexo.html");

?>

Most likely in your mysql table tbl_orders was set column with primary_key attribute, but without auto_increment attribute.

Example of adding attribute auto_increment (you need to change id name to your primary key column name):

ALTER TABLE tbl_orders MODIFY id int AUTO_INCREMENT;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM