Hey, I am creating a website with two forms which contain checkboxes and displays and sends the values input by the user to display on the page as well as save onto a database. The languages I'm using are xhtml, php and sql. The problem for me is that only one (usually the first value) sends over to the database if say for instance I select 3 checkboxes, what I need is for all the values to send over
Here is the coding.
Note: I've done alot of trial and error and nothing seems to be working for me. I would be very thankful if someone gave me a little hand.
XHTML:
<html>
<head>
<title>Form 7A</title>
</head>
<body>
<form action="Form7B.php" method="POST">
<p>Client ID:<input name="clientid" type="text" /></p>
<p>Company Name:<input name="name" type="text" /></p>
<input type="checkbox" name="worktype[]" value="Construction" />Construction<br />
<input type="checkbox" name="worktype[]" value="Civil" />Civil<br />
<input type="checkbox" name="worktype[]" value="Demolition" />Demolition<br />
<input type="checkbox" name="worktype[]" value="Industrial Manufacturing" />Industrial Manufacturing<br />
<input type="checkbox" name="worktype[]" value="Trades" />Trades<br />
<input name="" type="submit" value="Submit" />
<input name="" type="reset" value="Reset" />
</p>
</form>
</body>
</html>
PHP:
<html>
<head>
<title>Form 7B</title>
</head>
<body>
<?php
$host="localhost";
$user="root";
$password="";
$database="db2";
$clientid=$_POST['clientid'];
$name=$_POST['name'];
$mysqli=mysqli_connect($host,$user,$password,$database);
echo "<strong>Client ID:</strong>".$clientid."<br />";
echo "<strong>Name:</strong>".$name."<br />";
if(!empty($_POST["worktype"]))
{
echo"<ul>";
foreach($_POST["worktype"] as $value)
{
echo "<li>$value</li>";
$sqli="INSERT into client VALUES('$clientid','$name','$value')";
$result=mysqli_query($mysqli,$sqli);
}
echo"</ul>";
}
?>
</body>
</html>
Thanks in advance.
Ax.