通过php在mysql表中插入多行 [英] multiple row insertion in mysql table through php

查看:57
本文介绍了通过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')";

这篇关于通过php在mysql表中插入多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆