did php support or allow to add many record at one time in MySql Database ?..

i need 2 add all the student mark the same time

dis is my php script form..

<?php

echo"<form name='kptm' form method='POST' action='3.php'>";
echo"<h1 align='center'> Final Mark</h1>";

echo"<table border='2'>";

echo"<p align='center'>SUBJECT : UNIX SYSTEM (TK 213)";
echo "<tr> ";
echo"<td width='20'>Num";
echo"<td width='230'> STUDENT NAME";
echo"<td width='60'> TEST 1 &nbsp&nbsp n/15";
echo"<td width='60'> TEST 2 &nbsp&nbsp n/15";
echo"<td width='70'> PROJECT &nbsp&nbsp n/15";
echo"<td width='40'> QUIZ &nbsp&nbsp n/5";
echo"<td width='60'> CARRY MARK &nbsp&nbsp&nbsp n/50";

echo"</tr>";
echo"</table>";

$i=1;
while($i<=18)
{


echo"<table border='2'>";

echo "<tr> ";
echo"<td width='20'>$i ";
echo"<td><input type='text' name='name' size='35' >";
echo"<td><input type='text' name='test1' size='6' max length='5' > ";
echo"<td><input type='text' name='test2' size='6' max length=''> ";
echo"<td><input type='text' name='project' size='7' max length='5'> ";
echo"<td><input type='text' name='quiz' size='3' max length='5 '> ";
echo"<td><input type='text' name='carrymark' size='5' > ";
echo"</tr>";

$i++;


echo"</table>";

}

echo"<p>";
echo"<p>";
echo"<p>";
echo"<p>";
echo"<p>";
echo"<p align='center'><input type='submit' value='SAVE' >";

?>


And,dis is my Sql insert statements...

<?php

$Name = $_POST["name"];
$Test1 = $_POST["test1"];
$Test2 =$_POST["test2"];
$Project = $_POST["project"];
$Quiz = $_POST["quiz"];
$Carry = $_POST["carrymark"];

$conn = mysql_connect("localhost","root","") or die ("Could Not Connect To Server");
$selection = mysql_select_db("kptm") or die ("Could Not Connect To Database");

$sql = "INSERT INTO tk213(NAME, TEST1, TEST2,PROJECT,QUIZ,CARRY)VALUES ('$Name', '$Test1', '$Test2','$Project','$Quiz','$Carry')";
$result = mysql_query($sql);

?>

plz,help me..tq..

Recommended Answers

All 5 Replies

What's wrong ? Are you getting any errors ?

yup..only 1 record added in MySql Database..i guess,all the record add in the database...do u know why?..its hard 4 me to explain my problem..i want all the 18 students name and marks added in one time..do u have any solution?...plzzz...

Obviously its adding 1 record because you have 1 sql statement to insert and you are not looping it either. In your html form, you should have different input elements name. For example, you can concatenate $i value with textbox name to give it a unique name. When the page is submitted, you can loop through the posted values and insert into the table. Just a small example.

<?php //page1.php
for ($i=1;$i<10;$i++){
	echo "<form name=update method=post action=page2.php>";
	echo "Name : <input type=text name=name_".$i.">\t";	
	echo "Marks1: <input type=text name=test1_".$i."><br />";
}
echo "<input type=submit name=submit value=submit>";
?>
<?php //page2.php
for ($i=1;$i<10;$i++){
	$name = "name_".$i;
	$new_name=$_POST[$name];
	$marks = "test1_".$i;
	$new_marks=$_POST[$marks];
	//database connection string
	$query="insert into table (col1,col2) values ('$new_name','$new_marks')";
	mysql_query($query);
}
echo "All names and marks are entered into the table !!";
?>

Hope it helps.

thanx buddy..its done..i appreciate urs..;-)..hope,u can help me if i have any problems...nice 2 know u..

you are welcome.. feel free to post your problems :) Someone or the other will help you out.. Cheers..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.