Alright I apologize for the completely uninformative title but i had no idea what to call it. Basically I have an array with multiple values and I only want information to be sent from certain forms if a certain value is met in the array.
<?php
if(isset($_POST['cb1'])) {
$cb1 = implode(",", $_POST['cb1']);
} else {
$cb1 = "";
}
?>
<?php
if(isset($_POST['cb2'])) {
$cb2 = implode(",", $_POST['cb2']);
} else {
$cb2 = "";
}
?>
<?php
if(isset($_POST['tutor'])) {
$tutor = implode(",", $_POST['tutor']);
} else {
$tutor = "";
}
?>
<?php
$con = mysqli_connect("localhost","root","admin","form_info");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/*mysql_connect("localhost","root","admin")or die("Cannot Connect");
mysql_select_db("form_info")or die("Cannot connect to database name");// connect to database db_name*/
/*Get Values from form*/
$todays_date="";
if(isset($_POST['todays_date'])){ $todays_date = $_POST['todays_date']; }
$student_fname="";
if(isset($_POST['student_fname'])){ $student_fname = $_POST['student_fname']; }
$student_lname="";
if(isset($_POST['student_lname'])){ $student_lname = $_POST['student_lname']; }
$student_id="";
if(isset($_POST['student_id'])){ $student_id = $_POST['student_id']; }
$contact_number="";
if(isset($_POST['contact_number'])){ $contact_number = $_POST['contact_number'];}
$student_email="";
if(isset($_POST['student_email'])){ $student_email = $_POST['student_email']; }
$tr_date="";
if(isset($_POST['tr_date'])){ $tr_date = $_POST['tr_date']; }
$start_time="";
if(isset($_POST['start_time'])){ $start_time = $_POST['start_time']; }
$finish_time="";
if(isset($_POST['finish_time'])){ $finish_time = $_POST['finish_time']; }
$course_num1="";
if(isset($_POST['course_num1'])){ $course_num1 = $_POST['course_num1']; }
$course_num2="";
if(isset($_POST['course_num2'])){ $course_num2 = $_POST['course_num2']; }
$course_num3="";
if(isset($_POST['course_num3'])){ $course_num3 = $_POST['course_num3']; }
$section_num1="";
if(isset($_POST['section_num1'])){ $section_num1 = $_POST['section_num1']; }
$section_num2="";
if(isset($_POST['section_num2'])){ $section_num2 = $_POST['section_num2']; }
$section_num3="";
if(isset($_POST['section_num3'])){ $section_num3 = $_POST['section_num3']; }
/*
if(isset($_POST['cb2'])&&$_POST['cb2']="Need Thoery Room") {
mysqli_query($con,"INSERT INTO student_info2 (todays_date, student_fname, student_lname, student_id, contact_number, student_email, cb1, cb2, tr_date, start_time, finish_time, tutor) VALUES( '$todays_date','$student_fname','$student_lname', '$student_id','$contact_number','$student_email','$cb1','$cb2','$tr_date','$start_time','$finish_time','$tutor')")
;
}
*/
if($cb2="Need Tutoring"){
mysqli_query($con,"INSERT INTO student_info2 (todays_date, student_fname, student_lname, student_id, contact_number, student_email, cb1, cb2, tutor, course_num1, course_num2, course_num3, section_num1, section_num2, section_num3) VALUES( '$todays_date','$student_fname','$student_lname', '$student_id','$contact_number','$student_email','$cb1','$cb2','$tutor','$course_num1','$course_num2','$course_num3','$section_num1','$section_num2','$section_num3')")
;
}
error_reporting(E_ALL ^ E_NOTICE);
if($_POST['cb2']!="Need Thoery Room" and $_POST['cb2']!="Need Tutoring") {
mysqli_query($con,"INSERT INTO student_info2 (todays_date, student_fname, student_lname, student_id, contact_number, student_email, cb1, cb2, tutor) VALUES( '$todays_date','$student_fname','$student_lname', '$student_id','$contact_number','$student_email','$cb1','$cb2','$tutor')")
;
}
?>
So this is my php and below is my html form. As you can see I tried to use an if statement but to be truthful I just don't know php very well yet and I feel like I'm missing something completely. To be specific as to what I'm trying to do: I want to only send the data in tr_date, start_time, and finish_time if the theory room checkbox is checked. I'm also plan on doing the same thing to the table data for when tutoring is checked.
<form action="info.php" method="post">
<b>Today's Date</b><input name="todays_date" type="text" id="todays_date"><br />
<b>Student Name:</b>
First:<input name="student_fname" type="text" id="student_fname">
Last:<input name="student_lname" type="text" id="student_lname"><br />
<b>Student ID:</b><input name="student_id" type="text" id="student_id"><br />
<b>Contact Number:</b><input name="contact_number" type="text" id="contact_number"><br />
<b>Email:</b><input name="student_email" type="text" id="student_email"><br />
<h2>I resquest help with my (Check all that apply):</h2>
<input name="cb1[]" type="checkbox" value="DreamSpark" />DreamSpark<br />
<input name="cb1[]" type="checkbox" value="Downloading Books"/>Downloading Books<br />
<input name="cb1[]" type="checkbox" value="VM Ware"/>VM Ware<br />
<input name="cb1[]" type="checkbox" value="Virtual Library"/>Virtual Library<br />
<input name="cb1[]" type="checkbox" value="Downloading Software"/>Downloading Software<br />
<input name="cb1[]" type="checkbox" value="Printing"/>Printing<br />
<h2>I request to speak with a student worker or Rob about (Check all that apply):</h2>
<input name="cb2[]" type="checkbox" value="Student Network Account Not Working" />Student Network Account Not Working<br />
<input name="cb2[]" type="checkbox" value="Student Email Not Working"/>Student Email Not Working<br />
<input name="cb2[]" type="checkbox" value="Student Portal Not Working"/>Student Portal Not Working<br />
<input name="cb2[]" type="checkbox" value="Student Wireless Not Working"/>Student Wireless Not Working<br />
<input name="cb2[]" type="checkbox" value="Need Online Class Help/ E-book reader"/>Need Online Class Help/ E-book reader<br />
<input name="cb2[]" type="checkbox" value="Need Theory Room"/>Need Theory Room for Capstone/Group Project<br />
Date:<input name="tr_date" type="text" id="tr_date">
Start Time:<input name="start_time" type="text" id="start_time">
Finish Time:<input name="finish_time" type="text" id="finish_time">
<br />
<input name="cb2[]" type="checkbox" value="Need Tutoring"/>Need Tutoring (Select tutor and Fill out "Course(s) for tutoring Schedule" Below)<br />
<input name="tutor[]" type="checkbox" value="DeMartino"/>DeMartino
<input name="tutor[]" type="checkbox" value="Kritzik"/>Kritzik
<input name="tutor[]" type="checkbox" value="Peisl"/>Peisl
<input name="tutor[]" type="checkbox" value="Hall"/>Hall
<br />
<br />
<table border="1" style="width:300px">
<tr>
<th colspan=2 >Course(s) for tutoring Schedule</th>
</tr>
<tr>
<th>Course Number</th>
<th>Section Number</th>
</tr>
<tr>
<td><input name="course_num1" type="text" id="course_num1"></td>
<td><input name="section_num1" type="text" id="section_num1"></td>
</tr>
<tr>
<td><input name="course_num2" type="text" id="course_num2"></td>
<td><input name="section_num2" type="text" id="section_num2"></td>
</tr>
<tr>
<td><input name="course_num3" type="text" id="course_num3"></td>
<td><input name="section_num3" type="text" id="section_num3"></td>
</tr>
</table>