Good Morning,
Im working on a larger project but i tried to do a simple page in order to check my work. php/mysql newb here. Sorry! :)
What im trying to accomplish is ultimately having a single user page shown with rows of tasks from a table and a single check mark in order to say if the user has completed the task or not by checking or unchecking the box.
For testing purposes, I have set up a table with rows labled testid, testdata and testcheck. The testid a INT(2)AutoIncrement and Primary and Unique, testdata is a VARCHAR(30) and testcheck is a TINYINT(1). The auto increment isnt really important because I manually populated all the rows. I have 5 rows (for the array sake) consisting of 1-5 testid, "testdata1-5" for testdata and either a 0 or a 1 for testcheck. The table is functioning fine and the database can be queried.
Here is the code for the php start page:
<html>
<?php
include_once('init.php');
$query = mysql_query("SELECT testid, testdata, testcheck FROM testtable");
?>
<h1>Test form for checkmarks</h1>
<form method="POST" action="testover.php">
<table border="1">
<tr>
<td>
Test ID
</td>
<td>
Test Data
</td>
<td>
Checked
</td>
<td>
Test Check
</td>
</tr>
<?php
while ( $row = mysql_fetch_assoc($query)) {
?>
<tr>
<td>
<?php echo $row['testid']; ?>
</td>
<td>
<?php echo $row['testdata']; ?>
</td>
<td>
<center><input type="checkbox" name="<?php $row['testid'] ?>" value="<?php $row['testcheck']; ?>" <?php if($row['testcheck']=='1'){echo 'checked';} ?>></center>
</td>
<td>
<center><?php echo $row['testcheck']; ?></center>
</td>
</tr>
<?php } ?>
</table>
<input type="submit" name="confirm" value="Confirm Details">
<a href="testcheck.php"><input type="button" value="Home"></a>
</form>
</html>
Ive been going back and forth trying to use an array for the inputs name (name="something[]") or the "isset" parameter but that is where my knowledge is failing. Ive read countless articles both here and on other websites and I cant seem to find the right code to use. Most sites have rows with multiple check boxes or a different layout of their table.
I posted here to hopefully be pointed in some direction as to how to update the DB with these values of the check marks.