Current summary of the problem: I am pulling in information from table ‘main’ that lists out Goal Number and Goal Name for a specific ID (there can be up to 10 rows). These are displayed in a table on the web page. I added checkboxes in the first column that reflect the amount of rows in the table. The code for this is below, this part is working correctly. The out put is 3 columns, Checkbox, Goal Number, Goal Name, and up to 10 rows depending on amount of information in the table for that specific ID.
goals.php
<tr>
<td valign=top colspan=3>
Current Goals<br>
<?php
//this data is being pulled from 'main'
$result = mysql_query("SELECT * FROM main WHERE idnumber = $idnumber ORDER BY goalnumber");
if ($result) {
$total_rows = mysql_numrows($result);
} else { $total_rows = 0; }
print "<table border=1 width=400>\n";
print "<tr> \n";
print "<th> Checkbox </th> \n";
print "<th> Goal Number </th> \n";
print "<th> Goal Name </th> \n";
print "</tr> \n";
//}
$i = 0;
while ( $i < $total_rows )
{
$goalno = intval(mysql_result($result, $i, "goalnumber"));
$goalname = mysql_result($result, $i, "goalname");
$goal_id = intval(mysql_result($result, $i, "goal_id"));
print "<tr> \n";
print "<td> <center><input type=\"checkbox\" name=\"goal_id_$i\" value=\"$goalnumber - $goalname\"></td> \n";
print "<td> $goalnumber </td> \n";
print "<td> $goalname </td> \n";
print "</tr> \n";
$i = $i + 1;
}
?>
</table>
</td>
Once a user checks anywhere from 1-10 of these checkboxes and submits the form, I need to pass the values of said selections to the db (each selection should be written to a new field in the db table ‘updated_goals’. On submit the below file gets called. Note that I am writing the checkbox value to a different table in the same db ‘updated_goals’. I am not sure where I am going wrong with the code, but the goal is to write the values of the checkbox, “$goalnumber – $goalname” into the goal_id field.
goals_submit.php
// process data in table: updated_goals
$query = "SELECT idnumber from updated_goals where idnumber = {$_POST['idnumber']}";
$result = mysql_query($query);
$total_rows = mysql_numrows($result);
//writing data to 'updated_goals'
if (isset($_POST ['goal_id_$i'])) { $goal_id = ReplaceQuotes($_POST['goal_id_$i']); } else { $goal_id = ""; }
$query = "INSERT INTO updated_goals ( ";
$query .= "goal_id ";
$query .= ") VALUES ( ";
$query .= "'$goal_id' ";
$query .= ")";
Possible solutions:
Change this line:
to
or
change this line
to
if array used for input name for example:
inputname[]
it can be get via POST or GET by $_POST[‘inputname’][index] or $_GET[‘inputname’][index]