4 Replies - 317 Views - Last Post: 18 January 2018 - 09:40 AM Rate Topic: -----

#1 tedchong   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 31-December 17

browser can't read the checkbox answer

Posted 17 January 2018 - 10:57 PM

After i selected the answer from the checkbox, the message pop up mentioned that the field is blank, this is one of the message i set in .php file. But, why the selected answer can't be red by the browser?

<form name="TutorRegister" method="post" action="TutorRegister.php" id="TutorRegister">
<div class="col-md-6">
<div class="form-group">
<fieldset>
<label class="heading"> Part/Full Time Tutor?</label><br>
<input type="checkbox" name="JobStatus[]" value="Full Time"/>&nbsp;Full Time</br>
<input type="checkbox" name="JobStatus[]" value="Part Time"/>&nbsp;Part Time</br>
</fieldset>
</div>
</div>
</form>



<?php
$servername = "xxxxxxxxxxxxxxxxx";
$dbusername = "xxxxxxxxx";
$dbpassword = "xxxxxxx";
$dbname = "xxxxxxx";

$Name = $_POST['Name'];
$Age = $_POST['Age'];
$Contact = $_POST['Contact'];
$Email = $_POST['Email'];
$Address = $_POST['Address'];
$JobStatus = $_POST['Jobstatus'];


// Create connection
$conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);

// Check connection
if($conn->connect_error) {
    die("Connection failed:" . $conn->connect_error);
}

if(empty($Name)) {
echo "Name can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Age)) {
echo "Name can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Contact)) {
echo "Name can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Email)) {
echo "Email can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Address)) {
echo "Address can not be blank. Please press back and correct the issue!";
die();
}
if(empty($JobStatus)) {
echo "Job Status can not be blank. Please press back and correct the issue!";
die();
}
if(empty($StudentGradeLevel)) {
echo "Student Grade Level can not be blank. Please press back and correct the issue!";
die();
}

<?php
$servername = "localhost:3306";
$dbusername = "tedchong_Ali";
$dbpassword = "tuition19809754";
$dbname = "tedchong_tuition";

$Name = $_POST['Name'];
$Age = $_POST['Age'];
$Contact = $_POST['Contact'];
$Email = $_POST['Email'];
$Address = $_POST['Address'];
$JobStatus = $_POST['Jobstatus'];


// Create connection
$conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);

// Check connection
if($conn->connect_error) {
    die("Connection failed:" . $conn->connect_error);
}

if(empty($Name)) {
echo "Name can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Age)) {
echo "Name can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Contact)) {
echo "Name can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Email)) {
echo "Email can not be blank, Please press back and correct the issue!";
die();
}
if(empty($Address)) {
echo "Address can not be blank. Please press back and correct the issue!";
die();
}
if(empty($JobStatus)) {
echo "Job Status can not be blank. Please press back and correct the issue!";
die();
}
if(empty($StudentGradeLevel)) {
echo "Student Grade Level can not be blank. Please press back and correct the issue!";
die();
}

$JobStatus = $_POST['JobStatus'];
$my_JobStatus = "";
foreach($JobStatus as $range1) 
$my_JobStatus = $my_JobStatus . $range1 . " ";

mysql_query("INSERT INTO TutorRegisterForm(JobStatus) VALUES ('$my_JobStatus')") or die (mysql_error());

$StudentGradeLevel = $_POST['StudentGradeLevel'];
$my_StudentGradeLevel = "";
foreach($StudentGradeLevel as $range) 
$my_StudentGradeLevel = $my_StudentGradeLevel . $range . " ";

mysql_query("INSERT INTO TutorRegisterForm(StudentGradeLevel) VALUES ('$my_StudentGradeLevel')") or die (mysql_error());

$sql = "INSERT INTO TutorRegisterForm(Name,Age,Contact,Email,Address,JobStatus)
Values ('$Name','$Age,'$Contact','$Email','$Address','$JobStatus')";

if ($conn->query($sql) === TRUE) {
  echo '<script>alert("Your message successfully sent"); location.replace(document.referrer);</script>'; 
} else {
  echo "Error: ". $sql ."<br>" . $conn->error;                                  
}

$JobStatus = $_POST['JobStatus'];
$my_JobStatus = "";
foreach($JobStatus as $range1) 
$my_JobStatus = $my_JobStatus . $range1 . " ";

mysql_query("INSERT INTO TutorRegisterForm(JobStatus) VALUES ('$my_JobStatus')") or die (mysql_error());

$StudentGradeLevel = $_POST['StudentGradeLevel'];
$my_StudentGradeLevel = "";
foreach($StudentGradeLevel as $range) 
$my_StudentGradeLevel = $my_StudentGradeLevel . $range . " ";

mysql_query("INSERT INTO TutorRegisterForm(StudentGradeLevel) VALUES ('$my_StudentGradeLevel')") or die (mysql_error());

$sql = "INSERT INTO TutorRegisterForm(Name,Age,Contact,Email,Address,JobStatus)
Values ('$Name','$Age,'$Contact','$Email','$Address','$JobStatus')";

if ($conn->query($sql) === TRUE) {
  echo '<script>alert("Your message successfully sent"); location.replace(document.referrer);</script>'; 
} else {
  echo "Error: ". $sql ."<br>" . $conn->error;                                  
}


$conn->close();
?>




Is This A Good Question/Topic? 0
  • +

Replies To: browser can't read the checkbox answer

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4212
  • View blog
  • Posts: 13,303
  • Joined: 08-June 10

Re: browser can't read the checkbox answer

Posted 18 January 2018 - 02:23 AM

because forms canít be nested.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • So Smart! S-M-R-T!
  • member icon

Reputation: 6578
  • View blog
  • Posts: 26,719
  • Joined: 12-December 12

Re: browser can't read the checkbox answer

Posted 18 January 2018 - 02:23 AM

Where are your Name, Age, etc., fields in the form? Attempting to read non-existent post-values will cause errors. So your first step should be to check if there is any posted data.

You should not mix the obsolete mysql and mysqli extension libraries. Use mysqli or PDO solely.

A first debugging step is to print out the content of the post array, print_r($_POST).

But your very first step is to replace all mysql extension code.

Read this, Progressive Testing

Your error messages need correcting as you refer to "Name" thrice.

You also must use prepared statements to secure your processing.



Are there two separate PHP files there? It is a little confusing that they are blocked together as one.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • So Smart! S-M-R-T!
  • member icon

Reputation: 6578
  • View blog
  • Posts: 26,719
  • Joined: 12-December 12

Re: browser can't read the checkbox answer

Posted 18 January 2018 - 02:44 AM

Topic moved to PHP forum.
Was This Post Helpful? 0
  • +
  • -

#5 benanamen   User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 179
  • Joined: 28-March 15

Re: browser can't read the checkbox answer

Posted 18 January 2018 - 09:40 AM

This code is a classic example of everything that could be wrong, is wrong. The entire thing is junk. STOP what your doing and study this tutorial on how to use PDO. Come back with your updated code if you get stuck. There is no point doing anything with this code except deleting it.

PDO Tutorial
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1