I'm trying to insert multiple rows in a while loop with a form using implode but cannot seem to make it work. I want to insert multiple values named "weight". Like values 30,20,15,10,5 and the remaining emp_id and task_id.
page1.php
$sql = mysql_query("SELECT
task_tbl.task_id,
task_tbl.task_name,
task_tbl.task_sem,
task_tbl.task_yr,
task_tbl.post_id,
post_tbl.post_id,
post_tbl.post_name AS ppost_name
FROM
task_tbl
LEFT JOIN
post_tbl
ON
task_tbl.post_id = post_tbl.post_id
WHERE
task_sem = '$sem'
AND
task_yr = '$yr'
ORDER BY
task_id ASC");
echo '<form action = "upds_peval.php" name = "add" method = "post">';
while($row = mysql_fetch_assoc($sql)){
echo "<br/>";
echo "<b>Employee ID No.:</b>";
echo '<input size = "2" type = "text" name = "emp_id'.$id.'" value = "';
echo $_POST['emp_id'];
echo '"/>';
echo "<br/>";
echo "<b>Work/Activity ID No.:</b> ";
echo '<input size = "2" type = "text" name = "task_id'.$row['task_id'].'" value = "';
echo $row['task_id'];
echo '"/>';
echo "<br/>";
echo "<b>Work/Activity:</b> ";
echo $row['task_name'];
echo "<br/>";
echo "<b>Weight:</b> ";
echo '<input size = "1" type="text" name="weight" value = ""/>';
echo "%";
echo "<br/>";
}
echo '<input type="submit" name="submit" value="ADD"/>';
echo "</form>";
the output would be like:
Employee ID No.: 1001 Work/Activity ID No.: 2002 Work/Activity: Supervises Maintenance and Troubleshooting of Computers Weight: [__]%
Employee ID No.: 1001 Work/Activity ID No.: 2003 Work/Activity: Supervises Software Installation and Maintenance Weight: [__]%
Employee ID No.: 1001 Work/Activity ID No.: 2004 Work/Activity: Maintains, Monitors, and Troubleshoots Virtual Terminals Weight: [__]%
|SUBMIT|
page2.php
mysql_connect ("localhost", "root","") or die (mysql_error());
mysql_select_db ("emp_db0");
if(isset($_POST['submit'])){
$_POST['weight'];
$vals=implode(",",$_POST);
error_reporting(E_ALL ^ E_NOTICE);
mysql_query("INSERT INTO peval_tbl(weight,task_id,emp_id) VALUES('$vals')");
echo "<br/>";
echo "You have successfully added work/activities!";
echo "<br/>";
}