954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Beginner Question..?

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"";
echo" Final Mark";

echo"";

echo"SUBJECT : UNIX SYSTEM (TK 213)";
echo "


";
echo"Num";
echo" STUDENT NAME";
echo" TEST 1    n/15";
echo" TEST 2    n/15";
echo" PROJECT    n/15";
echo" QUIZ    n/5";
echo" CARRY MARK     n/50";

echo"";
echo"";


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


echo"";

echo " ";
echo"$i ";
echo"";
echo" ";
echo" ";
echo" ";
echo" ";
echo" ";
echo"";

$i++;


echo"";

}

echo"";
echo"

";
echo"

";
echo"

";
echo"

";
echo"

";

?>


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..

dbayo
Newbie Poster
16 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

What's wrong ? Are you getting any errors ?

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

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...

dbayo
Newbie Poster
16 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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.">";
}
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.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

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

dbayo
Newbie Poster
16 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You