Help with submitting multiple rows to a table - please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rp
Forum Newbie
Posts: 21
Joined: Wed Nov 24, 2004 5:49 am

Help with submitting multiple rows to a table - please

Post 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>";
User avatar
Crom
Forum Newbie
Posts: 8
Joined: Mon Nov 08, 2004 2:50 am
Location: Ukraine
Contact:

Post 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")
rp
Forum Newbie
Posts: 21
Joined: Wed Nov 24, 2004 5:49 am

Post 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
rp
Forum Newbie
Posts: 21
Joined: Wed Nov 24, 2004 5:49 am

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
Post Reply