簡體   English   中英

用php更新html表單

[英]html form updating with php

我正在嘗試使用下面的php和html代碼更新我的phpmyadmin數據庫:我已經成功添加了第一行數據,但是一旦我再次嘗試使用該表單,就無法添加另一行數據,除非我刪除了前一行我插入了數據庫。 簡而言之,我一次只能在數據庫中有1行。 謝謝你的幫助 :)

<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");

?>

最有可能在您的mysql表tbl_orders中設置了具有primary_key屬性但沒有auto_increment屬性的列。

添加屬性auto_increment示例(您需要將id名稱更改為您的主鍵列名稱):

ALTER TABLE tbl_orders MODIFY id int AUTO_INCREMENT;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM