I have asked for a little bit of help concerning other areas of this creation, but I still am not able to get it to work the way I want. So...I'll just post it all and see if anyone can help me. Thank you in advance for your time & help. 🙂
I'm trying to create a checklist for users so they can check off if they have a certain item or not. I want to insert it into the database where it's id, user, bear, checked. The code may be a bit sloppy since I've made several changes and have not bothered to clean it up...so perfectionists don't be offended! :p
<form action="$PHP_SELF" method="POST">
//db connection
$table = bears;
$user = 'christina'; //this is just for now
$result=mysql_query("SELECT * FROM $table") or die ("cant do it");
$row=mysql_fetch_array($result);
$id = $row["id"];
echo("<input type=\"hidden\" value=\"$id\">");
$num_rows = mysql_num_rows($result);
echo $num_rows;
//Now when they submit the form, I want it to insert the value into a new record corresponding to the checked item.
if($submit)
{
$checked = $_POST["bbname"];
echo "<BR>";
if (count($checked) > 0) // make sure we have something checked
{
$checkedx=1;
//I believe this is where my problem lies. When I echo this, I don't get the value of the textbox, just rather 'Array' for each of the items.
$namex=$_POST["bbname"];
echo $namex;
$checktable = checklist;
$sql = "INSERT INTO `checklist` VALUES ('$id','$user','$namex','$checkedx')";
$results = mysql_query($sql);
echo("Form submitted");
}
}
// My Form:
<?
echo("<form method=POST action=$PHP_SELF>");
for ($idx=1; $idx<$num_rows; $idx++)
{
$resultx=mysql_query("SELECT * FROM `$table`") or die ("cant do it");
$row=mysql_fetch_array($resultx);
$name = $row["name"];
echo("<input type=\"checkbox\" name=\"bbname[]\" value=\"$name\"> $name");
}
echo("<input type=\"submit\" name=\"submit\" value=\"Submit\"></form>");
?>
I just don't think my array is working.
Basically what I want to do is show a checkbox with a bear's name value next to it. When they check the box, a new record is added into the mysql db in terms of id, user, bear name, and an indication that it is checked (so if they choose to modify it, it can revert back to unchecked). If there are several to choose from, I only want the ones that are added to be inserted into the db.
As it stands now, everything goes in the db okay except for the bear name. I got 'Array' to go in there once, but now nothing is inserted.
Any help would be appreciated.
Thank you.
Christina