php - 将列从一个表复制到另一个表并从输入表单添加新列

标签 php mysql html

我可以将列从一个表复制到另一个表,但我的问题是在单个查询中从输入表单将数据插入到新表的列中

在这里,我想将这个 $tom 与“名称和价格”一起添加到列中,这个 $tom 来自另一个输入表单

<form method="post" enctype="multipart/form-data">
<input type="text" name="code" placeholder="Enter the Product Code" />
<button name="add_to_cart">Submit</button>
</form>
<?php
$db = mysqli_connect('localhost','root','','mainstock');
if(isset($_POST['add_to_cart']))
{
$tom = $_SESSION['cust'];
$code = $_POST['code'];
$query = "INSERT INTO sales (name,price,cust) SELECT name,price FROM tbl_product WHERE code = '$code' VALUES('{$tom}')";
$res = mysqli_query($db,$query);

最佳答案

我认为这是针对该查询的查询:

$query = "
    INSERT INTO sales (name,price,cust)
    SELECT name,price,'". $tom . "' FROM tbl_product;
";

关于php - 将列从一个表复制到另一个表并从输入表单添加新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54397698/

相关文章:

php - 修复 EXEC-php 中的插件 fatal error

php - 一个非常简单的自定义 PHP 框架中的自定义 404 错误页面

php - 棘手的 mysql 查询对多个类别的记录进行计数

php - 从 mysqli 语句结果返回关联数组

jquery - 根据用户点击显示嵌套的 ul

MYSQL:错误 1054 (42S22): 'id_employee' 中的未知列 'from clause'

mysql - 索引如何降低 MySQL 性能?

PHP 文件大小上传条件不起作用

html - 如何使用swift从aspx网站获取html

html - Wordpress CSS主题修改