Ok - I'm trying to figure out this code I've inherited. Essentially after a couple straight form inputs - it allows the user to view multiple table rows which contain various fields - then submits them to seperate tables - what I don't understand is how does the form know to NOT to insert rows that the user doesn't mess with - something tells me I can clean this up a lot better -
Can't I make this into one page? Also include some better usability/user feedback?
//text input for payperiodname
//text input for payperiod
for($i=0; $i < 3; $i++) {
if ($i % 2 == 0){
echo '<tr bgcolor="#CCCCCC">';
}else{
echo '<tr bgcolor="#e9e9f8">';
}
if ($i < 9){
echo '<td>'.($i+1).". ".' '.'<select name="sp'.$i.'">';
}else{
echo '<td>'.($i+1).". ".'<select name="sp'.$i.'">';
}
$sql5="Select * from tbl_sps where sp_id > 0 Order by sp_last_name,sp_first_name";
$result5=mysql_query($sql5, $connAdmin);
while($row5=mysql_fetch_array($result5))
{
echo '<option value="'.$row5['sp_id'].'">'.$row5['sp_last_name'].', '.$row5['sp_first_name'].'</option>';
}
echo '</select></td>';
echo '<td><select name="pt'.$i.'">';
$sql6="Select * from tbl_sp_payroll_types where sppt_id > 0 order by payroll_type_name";
$result6=mysql_query($sql6, $connAdmin);
while($row6=mysql_fetch_array($result6))
{
$ptcheck = $row6['sppt_id'];
if ($ptcheck == $payrate){
echo '<option value="'.$row6['sppt_id'].'" selected="selected">'.$row6['payroll_type_name'].'</option>';
}else{
echo '<option value="'.$row6['sppt_id'].'">'.$row6['payroll_type_name'].'</option>';
}
}
echo '</select></td>';
echo '<td bgcolor="999"><input size=9 type="text" name="date'.$i.'" value='.$payperiod.'>';
echo '<td><input size=4 type="text" name="hrs'.$i.'"></td>';
echo '<td><textarea name="notes'.$i.'" id="notes'.$i.'" cols="20" rows="2"></textarea></tr>';
}
And then this is how it gets processed on a submit page -
$Query="INSERT INTO tbl_payroll_wksht VALUES('$id', '$payperiodname', '$payperiod')";
mysql_query($Query, $connAdmin) or die ("Error inserting into tbl_payroll_wksht. Didn't Query"."<br>".mysql_error());
$query2 = "SELECT * FROM tbl_payroll_wksht WHERE name = '$payperiodname' and date = '$payperiod'";
$result = mysql_query($query2, $connAdmin) or die ("&Status=Error in query: $query. " .mysql_error());
$row = mysql_fetch_object($result);
$wksht_id = $row->wksht_id;
for($i=0;$i < 35;$i++)
{
$hours = "hrs".$i;
$$hours = $_POST[$hours];
$hours2 = $$hours;
$notes = "notes".$i;
$$notes = $_POST[$notes];
$notes2 = $$notes;
$date = "date".$i;
$$date = $_POST[$date];
$date2 = $$date;
//echo "hours=".$$hours."<br>";
$sp = "sp".$i;
$$sp = $_POST[$sp];
$sp2 = $$sp;
//echo "sp=".$$sp."<br>";
$pt = "pt".$i;
$$pt = $_POST[$pt];
$pt2 = $$pt;
//echo "pt=".$$pt."<br>";
if ($$hours != "" || $$hours != NULL){
$Query="INSERT INTO tbl_payroll VALUES('$id', '$wksht_id', '$sp2', '$hours2', '$pt2', '$date2', '$notes2')";
mysql_query($Query, $connAdmin) or die ("Didn't Query"."<br>".mysql_error());
}
}
echo "<b>Payroll submitted successfully!!<b>";