gpt4 book ai didi

php - 插入多个值 MySQL 和 PHP

转载 作者:行者123 更新时间:2023-11-29 10:01:17 24 4
gpt4 key购买 nike

我对 PHP 和 MySQL 完全陌生。我设法从表“产品”中添加 1 个值,但未能添加另一个值。

产品表中有两行,如下所示:

产品:

  • 产品名称
  • 产品价格

我的代码:

 $sql = "INSERT INTO products (product_name, user_id) VALUES (?, ?)";
$statement = $conn->prepare($sql);
$statement->bind_param('si', $_POST['product_name'], $_SESSION['user_id']);

if ($statement->execute()) {
redirect_to("/create.php?created=true");
} else {
echo "Error: " . $conn->error;
}

添加另一行“product_price”的正确方法是什么?

最佳答案

如果“products”表有一个变量“product_price”,那么您只需使用它的主 ID 进行更新即可。每个表必须有主ID以供识别。

关于php - 插入多个值 MySQL 和 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52897754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com