-1

我正在尝试从编辑页面将产品信息更新到 mysql 数据库中,但我显示它没有做任何事情,甚至没有显示任何错误。

我错过了什么?

<?php 
$dbcs = new mysqli("localhost", "root", "password", "shopping");


// Check connection
if (mysqli_connect_errno($dbcs))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
// Parse the form data and update company information to the system
if (isset($_POST['product_name'])) {

    $pid = $_POST['thisID'];
    $product_name = $_POST['product_name'];
    $product_category = $_POST['product_category'];
    $product_product_retail_price = $_POST['product_retail_price'];
    $product_price = $_POST['product_price'];

    // See if that company name is an identical match to another company in the system
    $sql = "UPDATE product SET
    product_name='$product_name', 
    product_category='$product_category', 
    product_retail_price='$product_retail_price',
    product_price='$product_price'
    WHERE product_id='$pid'" or die(mysql_error());  

    header("location: product.php");

    exit();
}


// Gather these companies full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
    $targetID = $_GET['pid'];
    $sql = "SELECT * FROM product WHERE product_id='$targetID' LIMIT 1";
  $result=mysqli_query($dbcs,$sql);

      while($row = mysqli_fetch_array($result)){ 
               $product_id = $row["product_id"];
             $product_name = $row["product_name"];
             $product_category = $row["product_category"];
             $product_retail_price = $row["product_retail_price"];
             $product_price = $row["product_price"];
             $screenshot =$row["screenshot"];
        }
}

mysqli_close($dbcs);
?>
4

3 回答 3

2
$sql = "UPDATE product SET
product_name='$product_name', 
product_category='$product_category', 
product_retail_price='$product_retail_price',
product_price='$product_price'
WHERE product_id='$pid'";

$query= mysqli_query($dbcs,$sql);

if(!$query)
{
print "error";

}
else 
{
header("your page link");
}

ps 感谢您的纠正 Hanky Panky :)

于 2013-10-12T17:04:11.657 回答
1

嗯...也许 $result = mysqli_query($dbcs,$sql);在定义插入 $sql 之后运行?

此外,不要在 $sql 字符串定义中使用 mysqli_query() 之后的 die()。

此外,在查询中使用它们之前,通过 mysqli_real_escape_string() 运行所有这些变量。

于 2013-10-12T16:58:33.147 回答
1

这是错误的:

$sql = "UPDATE product SET
    product_name='$product_name', 
    product_category='$product_category', 
    product_retail_price='$product_retail_price',
    product_price='$product_price'
    WHERE product_id='$pid'" or die(mysql_error());  

您没有执行该查询。执行它mysqli_query()

$sql = "UPDATE product SET
    product_name='$product_name', 
    product_category='$product_category', 
    product_retail_price='$product_retail_price',
    product_price='$product_price'
    WHERE product_id='$pid'";

$result = mysqli_query($dbcs,$sql);
于 2013-10-12T16:58:42.247 回答