php - mysql UPDATE 不更新 mysql 数据库并返回错误?

标签 php mysql

我真的不明白为什么要把这个简单的任务搞得这么复杂。我正在尝试更新 mysql 数据库,但无论我做什么,它都不会更新!

我也不断收到此通知消息..

Notice: Undefined index: thisID in

基本上我得到了所有字段中正确回显的值,但是当我按下提交按钮时我无法更新 mysql,我得到了上面的错误!

我像这样从 listing.php 解析信息/数据

<?php 
// This block grabs the whole list for viewing
$product_list = "";
$sql = "SELECT * FROM products ORDER BY date_added DESC";
$query = mysqli_query($db_conx, $sql);
$productCount = mysqli_num_rows($query); // count the output amount
if ($productCount > 0) {
    while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ 
             $id = $row["id"];
             $product_name = $row["product_name"];
             $price = $row["price"];
             $quantity = $row["quantity"];
             $shipping = $row["shipping"];
             $category = $row["category"];
             $manufactor = $row["manufactor"];
             $special = $row["special"];
             $stock = $row["stock"];
             $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
             $product_list .= "Product ID: $id - <strong>$product_name</strong> - £$price - <em>Added $date_added</em> &nbsp; &nbsp; &nbsp; <a href='edit.php?pid=$id'>edit</a> &bull; <a href='listing.php?deleteid=$id'>delete</a><br />";
    }
} else {
    $product_list = "You have no products listed in your store yet";
}
?>

这是编辑页面edit.php

<?php 
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {

      $pid = mysqli_real_escape_string($db_conx, $_POST['thisID']);
    $product_name = mysqli_real_escape_string($db_conx, $_POST['product_name']);
    $price = mysqli_real_escape_string($db_conx, $_POST['price']);
    $quantity = mysqli_real_escape_string($db_conx, $_POST['quantity']);
    $shipping = mysqli_real_escape_string($db_conx, $_POST['shipping']);
    $category = mysqli_real_escape_string($db_conx, $_POST['category']);
    $manufactor = mysqli_real_escape_string($db_conx, $_POST['manufactor']);
    $special = mysqli_real_escape_string($db_conx, $_POST['special']);
    $stock = mysqli_real_escape_string($db_conx, $_POST['stock']);
    $details = mysqli_real_escape_string($db_conx, $_POST['details']);
    // See if that product name is an identical match to another product in the system
    $sql = "UPDATE products SET product_name='$product_name', price='$price', quantity='$quantity', shipping='$shipping', category='$category', manufactor='$manufactor', special='$special', stock='$stock', details='$details', WHERE id=$pid";
    if (!$sql) {
    echo mysqli_errno($db_conx) . ": " . mysqli_error($db_conx) . "\n";
    die();
}
    $query = mysqli_query($db_conx, $sql);
    header("location:");
    exit();
}
?>

有人可以帮我解释一下吗?

提前致谢。

最佳答案

你的 `WHERE 子句之前有一个额外的逗号:

$sql = "UPDATE products SET product_name='$product_name', price='$price', quantity='$quantity', shipping='$shipping', category='$category', manufactor='$manufactor', special='$special', stock='$stock', details='$details', WHERE id=$pid";

只需删除它,你应该没问题:

$sql = "UPDATE products SET product_name='$product_name', price='$price', quantity='$quantity', shipping='$shipping', category='$category', manufactor='$manufactor', special='$special', stock='$stock', details='$details' WHERE id=$pid";

关于php - mysql UPDATE 不更新 mysql 数据库并返回错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21364293/

相关文章:

php - 如何通过 php 在 Html 按钮中使用 MySql

php - 使用 fgetcsv() 发出解析数据 - 期望参数为资源

java - Android Studio 错误 org.apache.http.conn.HttpHostConnectException : Connection to http://10. 0.2.2:8080 拒绝

java - 将带有 case 子句的 Sql 转换为 Hql

javascript - 仅将 Json 数组中的一定数量的行输出到 HTML 表

mysql - 在数据库中插入列表元素时创建 MySQL 唯一 ID

文件名的 PHP 正则表达式

javascript - Haar.js 将 open cv xml 转换为 javascript

java - 为 DateTime 列更新 MySQL 中的结果集

mysql - Mysql SELECT CASE WHEN表达式的使用方法