通过php在mysql表中插入多行

问题描述:

我刚刚在我的系统上安装了 xampp,并使用 php 在 mysql 中创建了连接和表,我什至在我的表中插入了一行,但是当我尝试插入多行时,流程直接转到我的自定义错误消息的其他部分.

I just installed xampp on my system and created connection and table in mysql using php and i even inserted one row in my table but when i tried to insert multiple rows then the flow directly gone to else part to my customize error message.

我的小代码如下:

<?php

include('connection_practice.php');
$insert_query="INSERT INTO student (NAME,ID,ADDRESS,SUBJECT,REMARKS)
               VALUES('AJAY',11,'SILK BOARD','IRO','AVERAGE'),
               VALUES('RITESH',12,'KARTHIK NAGAR','IRO','GOOD'),
               VALUES('SUNNY',13,'HEBBAL','HR MODULE','GOOD'),
               VALUES('HEMAVATHI',14,'HEBBAL','TME','GOOD'),
               VALUES('GURU',15,'HEBBAL','IRO','GOOD'),
               VALUES('SARITHA',16,'HEBBAL','IRO','GOOD'),
               VALUES('NIHAAR',17,'MULTIPLEX','COMPUTERS','AVERAGE')";

if(mysql_query($insert_query,$conn))
{
    echo "8 records added ";
} 
else
{
    echo "record not added ";
}

?>

我觉得应该是:

$insert_query = "INSERT INTO student (NAME, ID, ADDRESS, SUBJECT, REMARKS)
VALUES ('AJAY', 11, 'SILK BOARD', 'IRO', 'AVERAGE'),
('RITESH', 12, 'KARTHIK NAGAR', 'IRO', 'GOOD'), 
('SUNNY', 13, 'HEBBAL', 'HR MODULE', 'GOOD'), 
('HEMAVATHI', 14, 'HEBBAL', 'TME', 'GOOD'),
('GURU', 15, 'HEBBAL', 'IRO', 'GOOD'), 
('SARITHA', 16, 'HEBBAL', 'IRO', 'GOOD'),
('NIHAAR', 17, 'MULTIPLEX', 'COMPUTERS', 'AVERAGE')";