Page 1 of 1

Help with submitting multiple rows to a table - please

Posted: Wed Nov 24, 2004 6:10 am
by rp
Hi folks I am new to this forum, but I guess I may be in and out quiet a bit since I "lost" my php programmer and am having to learn whislt doing.

Can anybody please help with this little problem, I need to add mulitple rows to a DB table. Th form is built (that bit is easy) but when I try to sqlInsert I always get error messages. If someone could "ponit me" in the right direction I would be very happy.

The sqlinsert needs to be on the same page with a simple confirmation message. I can "sort out" which table etc it needs sent to but what I can't do is get multiple variables sent to the sqlInsert.

Here is my table (if it helps)

Code: Select all

echo "<div id='title'>";
echo "Training requests - job skills";
echo "</div>";
echo "<p>";
echo "<form name='trainingrequest' method='get' action='control.php?Employee=$Employee'>";
echo "<div id='col250'>";			
echo "Job Skill/s";
echo "</div>";
echo "<div id='col120'>";			
echo "Last assessed";
echo "</div>";
echo "<div id='col60'>";			
echo "Request";
echo "</div>";	
echo "<br>";
$sql = "SELECT * FROM jobtojobskills
LEFT JOIN jobskills ON(jobskills.JobSkillID = jobtojobskills.JobskillID)
LEFT JOIN employeejobskills ON(employeejobskills.JobSkillID=jobtojobskills.JobskillID)
WHERE jobtojobskills.Level>employeejobskills.EmployeeAcceptLevel
AND employeejobskills.EmployeeID='$Employee'
ORDER BY Date DESC";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC))
{ 
echo "<div id='col250'>";
echo $row['Skill'];
echo "</div>";
echo "<div id='col120'>";			
echo $row['Date'];
echo "</div>";
echo "<div id='col60'>";			
echo "<input name=skill[] type='checkbox' value=".$row['JobSkillID'].">";
echo "</div>";
echo "<br>";		
}
echo "<input name='request' type='submit'>";
echo "</fom>";

Posted: Wed Nov 24, 2004 7:41 am
by Crom
What kind of error do you get an what is structure of databases jobskills, jobtojobskills and employeejobskills?
You may first try to put this sql into one line (ie remove linebreak after "$sql = "SELECT * FROM jobtojobskills")

Posted: Wed Nov 24, 2004 8:34 am
by rp
Crom, Thanks for your reply, the line break is only there "in the forum" on the actual php page it deoesn't exist.

The error is quiet simple, I cannot get the "multiple" rows skill[] ti insert, I can get an accurate row count on submit, but the form always only ever adds the "last" record never all the records

Posted: Wed Nov 24, 2004 8:34 am
by rp
Crom, Thanks for your reply, the line break is only there "in the forum" on the actual php page it deoesn't exist.

The error is quiet simple, I cannot get the "multiple" rows skill[] ti insert, I can get an accurate row count on submit, but the form always only ever adds the "last" record never all the records

Posted: Wed Nov 24, 2004 9:15 am
by phpScott
I only see a select statement at the moment.

In your form with the checkboxes you name them name[] and I can only assume that each has a unique value.

When you submit the form you can do a simple for loop to cycle through all the check boxes and update the value ie:

Code: Select all

<?php
for($x=0; $x<count($_REQUEST['checkboxes']; $x++)
{
    //sql update statment here.
    //sumbit sql statement here.
}

?>
you get the idea :idea:

phpScott