Page 1 of 1

Help with Script - Need to work with Check Boxes

Posted: Tue Nov 30, 2010 9:04 am
by teparky
Hi All,

I am writing a Web Site that Reads some Data from a MySQL Database table and then shows it in a Table ina PHP Page. Once this data is displayed I want users to Tick boxes and then for the Page OR a Script to Read back in the Data that is ticked and then Write it to another Table in the SQL Database.

Here is the PHP To display the data from the First Table.
while($sSubject_row2 = mysql_fetch_array($result2))
{
if ($sSubject_row2['lilo'] == 'Outcome')
{

print'<tr><td>' .$sSubject_row2['UnitNumber'].'</td><td>'.$sSubject_row2['UnitName'].'</td><td>'.$sSubject_row2['lilo'].'</td><td>'.$sSubject_row2['Content'].'</td><td><input type="checkbox" name="check" id="check1"></td>';

}
}

Im just not quite sure how to write a script with Tick boxes and more than on tick box that may or may not be ticked.
Can someone please help me solve this issue.

Cheers

Re: Help with Script - Need to work with Check Boxes

Posted: Tue Nov 30, 2010 10:01 am
by curlybracket
It is the matter of correct name for checkboxes that will allow you to identify to which record each of them is bound. Instead of ordinary name for checkbox input, you have to add [] and make it an array:

Code: Select all

<td><input type="checkbox" name="check[checked]['.$sSubject_row2['id'].']"></td>
You also have to insert id of the record inside []. Now, after sending the form do print_r($_POST) and you will see how $_POST array looks now.

Re: Help with Script - Need to work with Check Boxes

Posted: Tue Nov 30, 2010 9:31 pm
by califdon
Before even thinking about the coding, my first question would be "Why are you doing this?" Every time I have ever seen a student reading data from a table and then writing (some of) it to another table in the same database, it's because the student doesn't understand databases. That's not something that is ever needed (now, someone will come along and think of some bizarre situation where it might be needed, I know, but certainly in 99.999% of cases, it is not needed).