我可以将列从一个表复制到另一个表,但是我的问题是在单个查询中通过输入表单在新表的列中插入数据
在这里,我想在此列中添加$ 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);
答案 0 :(得分:0)
我认为这是该查询:
$query = "
INSERT INTO sales (name,price,cust)
SELECT name,price,'". $tom . "' FROM tbl_product;
";