テーブルにデータを挿入しようとしたときに、次のエラーが発生しました。
[1064] SQL 構文にエラーがあります。'2','15','2013','12','5','51','PM','6',' 付近で使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。 15','44','PM')' 2 行目
フォームで複数のチェック ボックスを使用しています。このエラーを修正するにはどうすればよいですか?
挿入中のエラー: [1064] SQL 構文にエラーがあります。'2','15','2013','12','5','51','PM','6',' 付近で使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。 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 構文にエラーがあります。2 行目の「Fruit Dish,Coconut Pudding,Chocolate Banana Parfaits)」の近くで使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。