国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

可能的修訂標題:'PHP SQL 數(shù)據(jù)庫更新查詢問題:索引未定義且數(shù)據(jù)未更新?”
P粉637866931
P粉637866931 2024-04-02 18:46:20
0
1
741

我遇到無法更新數(shù)據(jù)庫的問題。我認為錯誤在于更新查詢本身,但我對 SQL 和 PHP 很陌生,因此我不能 100% 確定。任何幫助將不勝感激。

我收到了未定義的索引錯誤,我已修復(fù)該錯誤,但問題仍然存在:

$id = $_GET["id"];
$listdate = isset($_POST['list_date']) ? $_POST['list_date'] : '';
$listprice = isset($_POST['list_price']) ? $_POST['list_price'] : '';
$solddate = isset($_POST['sold_date']) ? $_POST['sold_date'] : '';
$soldprice = isset($_POST['sold_price']) ? $_POST['sold_price'] : '';
$shipdate = isset($_POST['ship_date']) ? $_POST['ship_date'] : '';
$shipcost = isset($_POST['ship_cost']) ? $_POST['ship_cost'] : '';

更改為上述代碼(不起作用)后,我仍然遇到更新數(shù)據(jù)庫的問題。這是完整的當前代碼:

<?

$id = $_GET["id"];
$listdate = $_POST["list_date"];
$listprice = $_POST["list_price"];
$solddate = $_POST["sold_date"];
$soldprice = $_POST["sold_price"];
$shipdate = $_POST["ship_date"];
$shipcost = $_POST["ship_cost"];

$servername = "localhost";
$username = "inventory";
$password = "*****";
$db = "products";

$conn = new mysqli($servername, $username, $password, $db);

if ($conn->connect_error){
    die("Connection failed: ". $conn->connect_error);
}

   
$sql = "UPDATE inventory SET list_date = '$listdate', list_price = '$listprice', sold_date = '$solddate', sold_price = '$soldprice', ship_date = '$shipdate', ship_cost= '$shipcost' WHERE product_id = ' .$id. '";

if($conn->query($sql) === TRUE){
    echo "Record Saved.";
    } else {
        echo "Error!";
    }

$conn->close();

?>

即使我手動將 ID 更改為數(shù)據(jù)庫分配的 ID,更新仍然不起作用,并且數(shù)據(jù)庫中沒有任何更改。我知道該表格看起來不太漂亮,但我將其設(shè)置為測試。以下是我如何設(shè)置表單來捕獲更改:

<form action="/SulleySells/scripts/updateitem.php?id=<?php echo $id;?>" method="post">

    <script type="text/javascript">
        function ShowHideDiv(listed) {
            var updatel = document.getElementById("updatel");
            updatel.style.display = listed.checked ? "block" : "none";
        }
        function ShowHideDiv2(sold) {
            var updates = document.getElementById("updates");
            updates.style.display = sold.checked ? "block" : "none";
        }
    </script>
    
    <label for="listed">
    <input type="checkbox" id="listed" onclick="ShowHideDiv(this)" />
    Listed?
    </label>
    
    <label for="sold">
    <input type="checkbox" id="sold" onclick="ShowHideDiv2(this)" />
    Sold?
    </label>
    
    <hr>
    
    <div id="updatel" style="display: none">
        <h3>Update Listing Details:</h3>
        <label for="listdate">Listed Date:</label>
        <input type="date" id="updateltext" name="listdate" value=""/>
        <br>
        <label for="listprice">Listed Price:</label>
        <input type="text" id="updateltext"  name="listprice" value=""/>
        <br>
        <button>Update</button>
        <hr>
    </div>
    
     <div id="updates" style="display: none">
         <h3>Update Sale Details:</h3>
         
        <label for="solddate">Sold Date:</label>
        <input type="date" id="updatestext" name="solddate" value=""/>
        <br>
        <label for="soldprice">Sold Price:</label>
        <input type="text" id="updatestext" name="soldprice" value=""/>
        <br>
        <label for="shipdate">Ship Date:</label>
        <input type="date" id="updatestext" name="shipdate" value=""/>
        <br>
        <label for="shipcost">Ship Cost:</label>
        <input type="text" id="updatestext" name="shipcost"value=""/>
        <br>
        <button>Update Sold Info</button>
        <hr>
    </div>

    </form>

P粉637866931
P粉637866931

全部回復(fù)(1)
P粉415632319

首先你必須改變:

至:

匹配您的 php 代碼中的內(nèi)容并將其應(yīng)用到其余的 html 輸入

然后更改:

WHERE product_id = ' .$id. '

至:

WHERE product_id = '$id'

通知 不要忘記在輸入中使用 id="" 格式化標簽中的 for="" ,以免給出不同的結(jié)果

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板