Insert multiple rows by one mysql query

Tje123

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");
Junius L.

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);

enter image description here

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Multiple MySQL rows with one form

分類Dev

MySQL INSERT INTO from PHP://INPUT multiple rows

分類Dev

How can I insert multiple records in mysql using php at once with one query dynamicaly?

分類Dev

Python Mysql CREATE and INSERT in one query

分類Dev

VERTICA insert multiple rows in one statement with named columns

分類Dev

Insert multiple rows from two tables into one table

分類Dev

PHP/MySQL; For loop to to insert rows only adds one

分類Dev

How to insert multiple, increasing by 1, rows to mysql database with php

分類Dev

PHP - PDO - How to fetch multiple rows with only one query?

分類Dev

MySql query to get rows with only one connected row

分類Dev

MySQL query to update multiple rows based on a column using php

分類Dev

MYSQL- Update multiple rows with one submit button

分類Dev

php mysql(INSERT QUERY)

分類Dev

mysql insert into query not working

分類Dev

Multiple rows to one column

分類Dev

SQL - Multiple Rows Into One

分類Dev

For Loop to insert multiple rows in SQL

分類Dev

mysql query to count no of rows in joining three tables and count rows of one table

分類Dev

MySQL count across multiple columns, with subquery, with one result query

分類Dev

Insert multiple values from one table to another using eloquent/query builder

分類Dev

one to one result in mysql Query

分類Dev

Mysql INSERT query inserts zeroes

分類Dev

MYSQL INSERT INTO FROM SELECT QUERY

分類Dev

How to combine multiple rows into one rows in SQL

分類Dev

SQL Combining multiple rows into one

分類Dev

Convert one column to multiple rows

分類Dev

Duplicate rows after a MySQL query

分類Dev

mysql query returning double rows

分類Dev

MySQL query - multiple JOIN

Related 関連記事

ホットタグ

アーカイブ