I'm trying to insert multiple rows by one mysql query.this is my full code.but it's didn't work.it's display error.
$res_name=$_POST['res_name'];
$mail=$_SESSION["email"];
$sql="INSERT INTO opening
(res_id,res_name,email,day,start,end)
VALUES
(NULL,'$res_name','$mail','monday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Tuesday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Wednesday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Thursday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Friday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Saturday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Sunday','00:00:00','00:00:00')";
$result=mysql_query($sql)or die ("Error");
I don't know how you connect to your database but there's nothing wrong with your script. I have tested it with PDO
, mysqli_query
and mysql_query
and it's working fine. below is the code I have used to test.
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "data";
$con = mysql_connect($servername, $username, $password) or
die("Could not connect: " . mysql_error());
mysql_select_db($dbname);
$res_name="JHB";
$mail="[email protected]";
$sql="INSERT INTO opening
(res_id,res_name,email,day,start,end)
VALUES
(NULL,'$res_name','$mail','monday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Tuesday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Wednesday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Thursday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Friday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Saturday','00:00:00','00:00:00'),
(NULL,'$res_name','$mail','Sunday','00:00:00','00:00:00')";
$result = mysql_query($sql);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加