* Matric,Cat_name和Product_name - 检索的数据 *查询$ sql
时出错if (isset($_POST['add'])) {
$Matric = $_POST['Matric'];
$Total_sales = $_POST['Total_sales'];
$Cat_name= addslashes($_POST['Cat_name']);
$Product = addslashes($_POST['Product_name']);
$tarikh = addslashes($_POST['Date']);
$data = "SELECT participant.*,sales.* FROM participant
LEFT JOIN sales ON sales.Matric = participant.Matric
WHERE sales.Product_name='$Product'" ;
$result = mysql_query($data) or die('SQL error');
$row = mysql_fetch_assoc($result);
$gambar = $row['img'];
echo $Matric;
echo $Total_sales;
echo $Cat_name;
echo $Product;
echo $tarikh;
echo $gambar;
$sql="INSERT INTO sales (Matric, Total_sales, Cat_name, Product_name, img, Date) values ('$Matric', '$Total_sales', '$Cat_name', '$Product', '$gambar', '$tarikh')";
$result=mysql_query($sql) or die("Suck");
if ($result)
echo 'Add success';
else
echo 'Add fail';
}
答案 0 :(得分:4)
Date是一个保留关键字,使用反引号运算符来逃避它
$sql="INSERT INTO sales (Matric, Total_sales, Cat_name, Product_name, img, `Date`) values ('$Matric', '$Total_sales', '$Cat_name', '$Product', '$gambar', '$tarikh')";
答案 1 :(得分:2)
答案 2 :(得分:0)
$sql="INSERT INTO sales (Matric, Total_sales, Cat_name, Product_name, img, `Date`) values ('{$Matric}', '{$Total_sales}', '{$Cat_name}', '{$Product}', '{$gambar}', '{$tarikh}')";
“”下的变量用于{}
答案 3 :(得分:-1)
日期是保留关键字。使用任何其他名称。