Forum Moderators: coopster

Message Too Old, No Replies

checkbox array

         

nshack31

5:15 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



I have an array of checkboxes...

$sixty = "<input type=\"checkbox\" name=\"mychk[]\" value=\"sixty\">";

$hundred = "<input type=\"checkbox\" name=\"mychk[]\" value=\"hundred\">";

I then use code to see which boxes have been checked and insert them into the database..

if(!empty($_GET['mychk'])) {
echo 'You selected: ' . implode(',', $_GET['mychk']);
} else {
echo 'You didn\'t select anything.';
}

$query="INSERT INTO members (sixty, hundred) VALUES ('$sixty', '$hundred')";
mysql_query($query) or die('Error, insert query failed');

The page successfully echoes which boxes you have checked but the problem is that the values of the checkboxes are not being inserted into the database

can anybody help?
thanks

[edited by: jatar_k at 5:40 pm (utc) on Aug. 16, 2005]
[edit reason] removed code tags [/edit]

jatar_k

5:43 pm on Aug 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$query="INSERT INTO members (sixty, hundred) VALUES ('$sixty', '$hundred')";

your vars should still be in the $_GET superglobal array so you will need to access them there

that query doesn't really make sense to me either. The columns are named sixty and hundred. What do you want to insert in there? yes and no? the same name as the column?

try this to see what you are looking for (I see your form is using GET, you might want to switch to POST)

if(!empty($_GET['mychk'])) {
echo 'You selected: ' . implode(',', $_GET['mychk']);
} else {
echo 'You didn\'t select anything.';
}

echo '<p><pre>';
print_r($_GET);
echo '</pre>';

$query="INSERT INTO members (sixty, hundred) VALUES ('$sixty', '$hundred')";
echo '<p>',$query;
mysql_query($query) or die('Error, insert query failed: ' . mysql_error());

those changes will help debug your script and see what is happening