尝试将数据插入表中时遇到以下错误:
[1064] 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 '2','15','2013','12','5','51','PM','6',' 附近使用正确的语法15','44','PM')' 在第 2 行
我在表单中使用了多个复选框。我该如何纠正这个错误?
插入时出错:[1064] 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 '2','15','2013','12','5','51','PM','6',' 附近使用正确的语法15','44','PM')' 在第 2 行
我在表单中使用多个复选框
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="shree"; // Database name
$tbl_name="order_people"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$first=$_POST['first'];
$last=$_POST['last'];
$email=$_POST['email'];
$number=$_POST['number'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$country=$_POST['country'];
$event=$_POST['event'];
$package=$_POST['package'];
$food_type=$_POST['food_type'];
$menu=$_POST['menu'];
$starters=$_POST['starters'];
$cold_drinks=$_POST['cold_drinks'];
$fast_food=$_POST['fast_food'];
$gujrati=$_POST['gujrati'];
$jain=$_POST['jain'];
$marathi=$_POST['marathi'];
$chinese=$_POST['chinese'];
$punjabi=$_POST['punjabi'];
$south_indian=$_POST['south_indian'];
$desserts=$_POST['desserts'];
$month=$_POST['month'];
$date=$_POST['date'];
$year=$_POST['year'];
$hours=$_POST['hours'];
$minutes=$_POST['minutes'];
$seconds=$_POST['seconds'];
$ampm=$_POST['ampm'];
$hours1=$_POST['hours1'];
$minutes1=$_POST['minutes1'];
$seconds1=$_POST['seconds1'];
$ampm1=$_POST['ampm1'];
$event = implode(",", $_POST['event']);
$food_type = implode(",", $_POST['food_type']);
$starters = implode(",", $_POST['starters']);
$cold_drinks = implode(",", $_POST['cold_drinks']);
$fast_food = implode(",", $_POST['fast_food']);
$jain = implode(",", $_POST['jain']);
$gujrati = implode(",", $_POST['gujrati']);
$marathi = implode(",", $_POST['marathi']);
$chinese = implode(",", $_POST['chinese']);
$punjabi = implode(",", $_POST['punjabi']);
$south_indian = implode(",", $_POST['south_indian']);
$desserts = implode(",", $_POST['desserts']);
// Insert data into mysql
$sql = "INSERT INTO $tbl_name(first,last,email,number,address,address1,city,state,zip,country,event,package,food_type,menu,starters,cold_drinks,fast_food,jain,gujrati,marathi,chinese,punjabi,south_indian,desserts)
VALUES('$first','$last','$email','$number','$address','$address1','$city','$state','$zip','$country','$event','$package','$food_type','$menu','$starters','$cold_drinks','$fast_food','$jain','$gujrati','$marathi','$chinese','$punjabi','$south_indian','$desserts)";
echo ($sql);
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='form.php'>Back to main page</a>";
}
else {
echo 'error while inserting : ['.mysql_errno().'] '.mysql_error();;
}
?>
SQL
INSERT INTO order_people(
first,last,email,number,address,address1,city,state,zip,country,
event,package,food_type,menu,starters,cold_drinks,fast_food,jain,
gujrati,marathi,chinese,punjabi,south_indian,desserts
) VALUES(
'Akshay','Desai','akshaydesai@mail.com','99846464','dihqwolhwoh','efhowhefop',
'sifgoigfo','maharashtra','mumbai','India','Birthday Parties','1','Non-Vegetarian','',
'Wontons Crab and Goons,Cucumber Mousse,Baked Shrimp Rangoon','Soft Drinks,Smoothies',
'Aloo Tikki,Bhajiya,Bhel','Green Gram Dhokla,Jain Gawar Ki Sabji,Jain Spicy Sprouts Pulav,Jain Upma',
'Stuffed Lady Finger,Surti Papdi Shaak,Dahi Vada,Singoda Na Bhajia','Chicken Biryani,Aloo Vadi,Bharli Vangi',
'Chinese Noodles,Chicken with Brocoli and Rice,Chinese Veg Noodles','Aloo Amritsari,Chana Dal Paratha,Punjabi Kadi Pakoda,Punjabi Kadhi',
'1,1','Fruit Dish,Coconut Pudding,Chocolate Banana Parfaits
)
插入时出错:
[1064] 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的“水果盘、椰子布丁、巧克力香蕉冻糕)附近使用正确的语法