Hi Guys,
I am currently working on a simple project for myself and I am a bit stuck. I've searched google for days and can not get a straight answer.
I am setting up a sort of roster site where I manually add members (no user accounts, just for statistics) and I want to be able to add stats to those members.
I've got everything else pretty much setup, but I am having trouble figuring out checkboxes. When I add a member I want to be able to select multiple "divisions" for the member. These will be listed on the stats page, and I want each of them to be listed.
So down to the actual issue I am having. I have (for the time being, will be adding upto 50) 4 divisions, on the form I have the division name with a checkbox beside it to add/remove this member from that division.
I have two tables setup in my database. I have one table for the member and their profile or stats. The other table I setup for the actual division names/description. The purpose for setting up two tables was because I've setup another script to add more divisions and descriptions.
My page to add a division to a certain member acts in the following manner: link contains the member id, and page uses GET to serach the member by ID. The form on this page will UPDATE the MEMBER where ID is $_GET['ID']
So I have two queries going at this time, one to get the member's id to update, and another to list all the available divisions and list them in a table with a checkbox for each. All this works fine, my problem is getting the checkbox values. I want to be able to store and update this data in the members table. The best way I can figure to do this is to store an integer corresponding to the ID number in the division table.
So is there a way that each checkbox would have a value and these values are stored in an array on a single column of the members table? And then how would I go about checking for this value on each checkbox using the WHILE function? Here is the code I have so far (I am still new at PHP so I know there is probably syntax errors)
<?php
if(isset($_POST['update']))
{
include "dbinfo.php";
$id = $_POST['id'];
$sql = "UPDATE members SET WHERE id=$id";
$retval = mysql_query( $sql );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($db);
}
else
{
?>
<?php
include "dbinfo.php";
$id=$_GET['id'];
$query = "SELECT * FROM members WHERE id='$id'";
$result = mysql_query($query);
if($result === FALSE) {
die(mysql_error());
}
$record = mysql_fetch_array($result);
$query2 = "SELECT * FROM divisions";
$result2 = mysql_query($query2);
if($result2 === FALSE) {
die(mysql_error());
}
?>
<h3>Updating divions for member: <?php echo $record ['member'];?></h3>
user's id: <?php echo $record ['id'];?>
<br>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="60%" border="1" align="left">
<th width="5%">id</th><th width="45%">division</th><th width="45%">image</th><th width="5%">status</th>
<?PHP while ($record2 = mysql_fetch_array($result2)){
echo "<tr><td>" . $record2 ['id'] . "</td>";
echo "<td>" . $record2 ['divname'] . "</td>";
echo "<td>" . $record2 ['divimg'] . "</td>";
echo '<td><input type="checkbox" name="' . $record2 ['divname'] . '" id="' . $record2 ['divname'] . '" value="' . $divstatus . '" /></td>';
echo '</tr>'; ///$divstatus will be my checked/unchecked value once I figure out how to fetch this
}?>
</table>
<input name="update" type="submit" id="update" value="Update">
</form>
<?php
} ///End Else
?>
Any help you could give would be much appreciated. Thank you for your time reading all of this!