Im having problems trying to insert an array:
here is my form which lists activities in an array called activity_checkbox
<?php
echo '<strong>Welcome</strong><br>';
?>
<?php echo $_SESSION['username'];?>
<?php
include ("connect.php");
// Get the activities
$sql_activity = "SELECT * FROM activity ORDER by activity";
$activity_result = mysql_query($sql_activity) or die("Error fetching activities: ".mysql_error());
$activity_array = mysql_fetch_assoc($activity_result);
?>
<?php
echo '<form name="searchform" method="GET" action="infolinks_choicesv4_formhandler.php">';
echo '
<table>
<tr>
<td>Select the activities:</td>
</tr>
<tr>
<td>';
while ($row = mysql_fetch_assoc($activity_result)) {
//foreach($activity_array as $activity){
echo '<input type="checkbox" name="activity_checkbox[]" value="'.$row['activity_id'].'">'.$row['activity'].'';
}
echo ('</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Search">
</td>
</tr>
</table>');
echo '</form>';
?>
and here is my formhandler- i have no error message as such - just "no activity selected" as set in my customised debugging handler
include("connect.php");
if(isset($_POST['submit']))
{
$username = $_SESSION['username'];
foreach($_POST['activity_checkbox'] as $value)
{
$sql = "INSERT INTO activityuser (username, activity) VALUES ($username, $value)";
$result = mysql_query($sql, $connection) or die(mysql_error());
//execute your query
print $result."<br/>";
}
}
else
//no activity selected
{
echo '<br/>No activities selected';
}
where have i gone wrong? i think it is where i handle the result of my query
thankyou in advance