I have three columns in the database table and want to add 0 to 3 values (topics) from the checkboxes into the columns.
HTML:
<ul class="checkbox" id="topicarea">
<li><input type="checkbox" name="topic[]" value="AG">Agriculture<br /></li>
<li><input type="checkbox" name="topic[]" value="ART">Art<br /></li>
<li><input type="checkbox" name="topic[]" value="BIO">Biological Sciences<br /></li>
<li><input type="checkbox" name="topic[]" value="BUS">Business<br /></li>
<li><input type="checkbox" name="topic[]" value="COM">Communication<br /></li>
<li><input type="checkbox" name="topic[]" value="IT">Information Technology<br /></li>
<li><input type="checkbox" name="topic[]" value="EDU">Education<br /></li>
<li><input type="checkbox" name="topic[]" value="ENGR">Engineering<br /></li>
<li><input type="checkbox" name="topic[]" value="ENVS">Environmental Science<br /></li>
<li><input type="checkbox" name="topic[]" value="HE">Health<br /></li>
<li><input type="checkbox" name="topic[]" value="LANGLIT">Language and Literature<br /></li>
<li><input type="checkbox" name="topic[]" value="LAW">Law<br /></li>
<li><input type="checkbox" name="topic[]" value="PHR">Philosophy and Religion<br /></li>
<li><input type="checkbox" name="topic[]" value="PHYS">Physical Science<br /></li>
<li><input type="checkbox" name="topic[]" value="PSY">Psychology and Counseling<br /></li>
<li><input type="checkbox" name="topic[]" value="RECFIT">Recreation and Fitness<br /></li>
<li><input type="checkbox" name="topic[]" value="CON">Skilled Trade and Construction<br /></li>
<li><input type="checkbox" name="topic[]" value="LIBART">Social Sciences and Liberal Arts<br /></li>
<li><input type="checkbox" name="topic[]" value="SOCSRV">Social Services<br /></li>
<li><input type="checkbox" name="topic[]" value="TRANS">Transportation<br /></li>
<li><input type="checkbox" name="topic[]" value="OTHER">Other<br /></li>
</ul>
PHP: I have set three variables (topics 1, 2, and 3) But I do not know what to set them to. I figure they must loop through the checkboxes and get set when they find a value? How can I capture 0 to 3 checked values so I can insert them?
<?php
include('local-connect.php');
$fname = mysqli_real_escape_string($dbc, $_POST['firstname']);
$lname = mysqli_real_escape_string($dbc, $_POST['lastname']);
$email = $_POST['email'];
$password = $_POST['pword'];
$address1 = $_POST['lineone'];
$address2 = $_POST['linetwo'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$ageGroup = $_POST['agegroup'];
$topic1 =
$topic2 =
$topic3 =
$bio = $_POST['bio'];
$profilePic = $_POST['fileToUpload'];
$query = "INSERT INTO teachers(fname, lname, email, pword, address1, address2, city, state, zip, phone, ageGroup, topic1, topic2, topic3, bio, profilePic)" .
"VALUES('$fname','$lname','$email','$password','$address1','$address2','$city','$state','$zip','$phone','$ageGroup','$topic','$bio','$profilePic')";
$result = mysqli_query($dbc, $query) or die('Unable to Connect to Database or the Registration is incomplete!');
mysqli_close($dbc);
?>