i have followed a tutorial for a working checkbox group after failed attempts with others.
On test file it was working but when i add it to my site i dont get any results after submitting form.
First of all here is the file from tutorial.
Sorry in advance for all the code.
<?php require_once('connection.php'); ?>
<?php
if (isset($_POST['submit']))
{
if (isset($_POST['check_list']))
{
$strcheck_list = implode(",", $_POST['check_list']);
}
else
{
$strcheck_list = "";
}
echo "Interested in: " . $strcheck_list;
exit();
}
?>
<html>
<head>
<title>Checkboxes</title>
</head>
<body>
<form action="" name="check_list" method="post">
<table width="900">
<tr>
<td width="225"><input type="checkbox" name="check_list[]" value="option1"><label>Option1</label></td>
<td width="225"><input type="checkbox" name="check_list[]" value="option2"><label>option2</label></td>
<td width="225"><input type="checkbox" name="check_list[]" value="option3"><label>option3</label></td>
<td width="225"><input type="checkbox" name="check_list[]" value="option4"><label>option4</label></td>
</tr>
</table>
</form>
</body>
</html>
Which has the desired effect of showing what ive chosen.
But then i when i try to go live with it i create a interests file and add the following:
<?php
include("config/db_connect.php");
// Check user id
if($_SESSION['userid']=="")
{
header("location: index.php");
}
if (isset($_POST['Submit']))
{
$insert = mysqli_query($conn,"update user_info set check_list = '".$_POST['check_list']."' where user_id = '".$_SESSION['last_id']."' ") or die(mysqli_error($conn));
if($insert)
{
header("location: profile.php");
}
}
?>
<html>
<head>
<title>Checkboxes</title>
</head>
<body>
<form action="" name="check_list" method="post">
<table width="900">
<tr>
<td width="225"><input type="checkbox" name="check_list[]" value="option1"><label>Option1</label></td>
<td width="225"><input type="checkbox" name="check_list[]" value="option2"><label>option2</label></td>
<td width="225"><input type="checkbox" name="check_list[]" value="option3"><label>option3</label></td>
<td width="225"><input type="checkbox" name="check_list[]" value="option4"><label>option4</label></td>
</tr>
</table>
</form>
</body>
</html>
And on the profile.php i had the following:
<?php if (isset($_POST['check_list']))
{
$strcheck_list = implode(",", $_POST['check_list']);
}
else
{
$strcheck_list = "You didnt select any interests";
}
echo "Interested in: " . $strcheck_list;
exit();?>
When i press submit i get You didnt select and interests
and when i go to the database i get array
any help would be much appreicated