abosami Posted August 10, 2010 Share Posted August 10, 2010 hi all ,, I have a table : test (id , name , title , area , city) and I want from user to insert more than one record .. I made the script but I don't know there are better than this code .. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>My test</title> </head> <body> <table align="center" width="70%"> <tr> <form action="<?php $_SERVER['PHP_SELF']?>?>" method="get"> <?php if($_GET['submit']){ $con = mysql_connect("localhost","root",""); $db = mysql_select_db("test",$con); for($i = 1 ; $i < 10 ; $i++){ $name = $_GET['name'.$i]; $title = $_GET['title'.$i]; $area = $_GET['area'.$i]; $city = $_GET['city'.$i]; $sql = "INSERT INTO `test`.`test` (`title` ,`name` ,`area` ,`city`)VALUES ( '$name', '$title', '$area', '$city');"; $query = mysql_query($sql , $con); } }else { $con = mysql_connect("localhost","root",""); $db = mysql_select_db("test",$con) or die (mysql_error()); echo '<tr><td>Name</td><td>Title</td><td>Area</td><td>City</td></tr>'; for ($i = 1 ; $i < 10 ; $i++){ echo '<tr><td><input type="text" name="title'.$i.'" /></td> <td><input type="text" name="name'.$i.'" /></td> <td><input type="text" name="area'.$i.'" /></td> <td><input type="text" name="city'.$i.'" /></td></tr> <br /> '; } echo '<tr><td colspan="4"><input type="submit" name="submit" value="submit" /></td></tr>'; } ?> </form> </tr> </table> </body> </html> I wait you to advise me and I want your opinion .. than you very much .. Quote Link to comment https://forums.phpfreaks.com/topic/210381-hi-all-i-want-to-insert-more-than-10-record-in-the-datea-base/ Share on other sites More sharing options...
gizmola Posted August 10, 2010 Share Posted August 10, 2010 You can insert multiple rows in one insert by adding to the VALUES LIST: insert into tbl (a, b, c) VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9) This example would insert 3 rows at once. Quote Link to comment https://forums.phpfreaks.com/topic/210381-hi-all-i-want-to-insert-more-than-10-record-in-the-datea-base/#findComment-1097816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.