Hi i'am try to insert multiple data on a single submit, but i'm a total noob to Arrays, can any one help me out here... one of the members send me this out, but still i can figure it out how to insert the fields onto my database. it inserts but doesnt get the valuee.. Please help!

if(isset($_POST['save']))
	{
	unset($_POST['save']);
	$i = count($_POST['id']); $x = 0;
	for($x=0; $x <$i;$x++){
		foreach($_POST as $data =>$d){
		echo $data.'-'.$d[$x].'<br/>';
		$insert = mysql_query("insert into tbl_grades");
		//sql statement here (example): insert into table name (value of $data) values( value of$d[$x]) -- 
[B]//HOW DO I MAKE MY SQL QUERY TO SAVE THIS OUT, I KNOW THIS IS MY PROBLEM IN THE QUERY....[/B]

HTML CODE:S/

<input name="id[]" type="hidden" value="<?php echo $row['id'];?>" />
 1st<input name="fg[]" type="text" id="fg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/>
 2nd<input name="sg[]" type="text" id="sg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/>
 3rd<input name="tg[]" type="text" id="tg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/>
4th <input name="forg[]" type="text" id="forg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/> ---- sub_id stands for subject id

Recommended Answers

All 4 Replies

Member Avatar for diafol

I tried answering this a few times, but then I thought, how are you producing the form fields? I'm assuming using a while... loop. Show more of this code.

IDs for form attributes shouldn't be array items. NAME attributes - OK.

yes im looping it together with the values i wanted.

sir, can you help me with this,

i can't get the value of what im trying to save....

Member Avatar for diafol

Yawn...

Show more of this code.

You're not helping yourself here...

Yawn...

You're not helping yourself here...

this is my code how i make the loop, together with the subject id i wanted to save..

<?php
	$query = mysql_query("select * from students, stud_subject, tc_handle,acad_year where
			tc_handle.sub_id = '$_GET[view]' and 
			tc_handle.acad_id=acad_year.acad_id and
			acad_year.acad_id='$g_year[acad_id]' and
			stud_subject.acad_id=acad_year.acad_id and
			students.id = stud_subject.id and
			stud_subject.sub_id = tc_handle.sub_id and 
			stud_subject.acad_id='$g_year[acad_id]'");
while ($row = mysql_fetch_array($query)){
?>
<?php
	$f_name = $row['lastname'].' ,&nbsp;'.$row['firstname'].'&nbsp;'.$row['middlename'].'<br>';
	echo '<p class="name">'.$f_name.'<p class="x">';
	
?>
<form action="tc_addall.php" method="post">
 <p class="oo">
 <input name="id[]" type="hidden" value="<?php echo $row['id'];?>" />
 1st<input name="fg[]" type="text" id="fg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/>
 2nd<input name="sg[]" type="text" id="sg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/>
 3rd<input name="tg[]" type="text" id="tg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/>
4th <input name="forg[]" type="text" id="forg[]" size="1" value="<?php  $g_sub['sub_id'];?>"/>
 </p>

<?php }?>
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.