我正在尝试通过一个mysql查询插入多行。这是我的完整代码。但是它没有工作。它的显示错误。
$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");
答案 0 :(得分:1)
INSERT INTO example
(example_id, name, value, other_value)
VALUES
(100, 'Name 1', 'Value 1', 'Other 1'),
(101, 'Name 2', 'Value 2', 'Other 2'),
(102, 'Name 3', 'Value 3', 'Other 3'),
(103, 'Name 4', 'Value 4', 'Other 4');
这对我有用。告诉我如果它不起作用会给你带来什么错误。
答案 1 :(得分:0)
我不知道您如何连接到您的数据库,但您的脚本没有任何问题。我已使用PDO
,mysqli_query
和mysql_query
对其进行了测试,并且工作正常。下面是我用来测试的代码。
$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="john@john.com";
$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);
答案 2 :(得分:0)
INSERT INTO person(
`id` ,
`name` ,
`email` ,
`phone`
)
VALUES
( 100, 'John Smith', 'email1@example.com', '09723282639' ) ,
( 101, 'Jane Doe', 'email2@example.com', '25655555' )