Can't insert multiple checkbox values to Mysql table

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 1342 Views - Last Post: 08 February 2018 - 06:49 PM Rate Topic: -----

#31 tedchong  Icon User is offline

  • New D.I.C Head

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

Re: Can't insert multiple checkbox values to Mysql table

Posted 03 February 2018 - 08:05 PM

Still the same , error message pop up. print_r($_POST); at line 26.

www.xxx.com is currently unable to handle this request.
" HTTP ERROR 500"


<?php
$servername = "xxxxxxxxxxxxxxx";
$dbusername = "xxxxxxxxxx";
$dbpassword = "xxxxxxxxxxxx";
$dbname = "xxxxxxxxxxxxxx";


try{
$conn = new PDO("mysql:host=$servername;dbname=$dbname",$dbusername,$dbpassword);
$conn ->setAttribute(
     // any occuring errors will be thrown as PDOException
	 PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION
	 );


  if (isset($_POST['submit'])) {
 
    $Name = $_POST['Name'];
    $Age = $_POST['Age'];
    $Contact = $_POST['Contact'];
    $Email = $_POST['Email'];
    $Address = $_POST['Address'];
    $JobStatus = $_POST['JobStatus'];
    $StudentGradeLevel = $_POST['StudentGradeLevel'];
    
    print_r($_POST);
//insert data query
$setup = $conn->prepare("
       INSERT INTO
	     TutorRegisterForm(Name,Age,Contact,Email,Address,JobStatus)
	   VALUES
         (:Name, :Age, :Contact, :Email, :Address, :JobStatus)"	   
);
$setup->bindParam(':Name',$Name);
$setup->bindParam(':Age',$Age);
$setup->bindParam(':Contact',$Contact);
$setup->bindParam(':Email',$Email);
$setup->bindParam(':Address',$Address);
$setup->bindParam(':JobStatus',$JobStatus);
$setup->execute();


//Write Checkbox values to DB

foreach($StudentGradeLevel as $Grade) {
    $setup_2 = $conn->prepare("
                  INSERT INTO 
                        TutorStudentGrade(StudentGradeLevel)
                        VALUES
                        (:Grade)");
    $setup_2->binParam(':Grade',$Grade);
    $setup_2->execute();
                        
} 
}
echo "New records created successfully!";
}
catch(PDOException $e)
{
echo "Error:" .$e->getMessage();
}
}
$conn = null;
?>




no values showing out

This post has been edited by tedchong: 03 February 2018 - 08:09 PM

Was This Post Helpful? 0
  • +
  • -

#32 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2389
  • View blog
  • Posts: 9,610
  • Joined: 03-December 12

Re: Can't insert multiple checkbox values to Mysql table

Posted 03 February 2018 - 08:16 PM

Develop locally with error reporting turned on.
Was This Post Helpful? 0
  • +
  • -

#33 tedchong  Icon User is offline

  • New D.I.C Head

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

Re: Can't insert multiple checkbox values to Mysql table

Posted 08 February 2018 - 06:48 PM

Result in page:
Array ( [Name] => Fong [Age] => 32 [Contact] => 0129980099 [Email] => [email protected] [Address] => 32, Jalan FF, Taman FF [EducationLevel] => Degree [JobStatus] => Part Time [StudentGradeLevel] => Array ( [0] => Primary School [1] => Form 1-3 [2] => Form 4-5 Science Class ) [submit] => submit )
Fatal error: Call to undefined method PDOStatement::binParam() in /home/Sense/public_html/Register.php on line 53

Line 53 in my IDE is $setup_2->binParam(':Grade',$Grade);
Why the line is undefined method? and how to solve this problem?

<?php
$servername = "xxxxxxxxxxxxxxx";
$dbusername = "xxxxxxxxxxxxxxxx";
$dbpassword = "xxxxxxxxxxxxxxxxxxx";
$dbname = "xxxxxxxxxxxxxxxxxx";


try{
$conn = new PDO("mysql:host=$servername;dbname=$dbname",$dbusername,$dbpassword);
$conn ->setAttribute(
     // any occuring errors will be thrown as PDOException
	 PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION
	 );


  if (isset($_POST['submit'])) {
 
    $Name = $_POST['Name'];
    $Age = $_POST['Age'];
    $Contact = $_POST['Contact'];
    $Email = $_POST['Email'];
    $Address = $_POST['Address'];
    $JobStatus = $_POST['JobStatus'];
    $StudentGradeLevel = $_POST['StudentGradeLevel'];
    
    print_r($_POST);
//insert data query
$setup = $conn->prepare("
       INSERT INTO
	     TutorRegisterForm(Name,Age,Contact,Email,Address,JobStatus)
	   VALUES
         (:Name, :Age, :Contact, :Email, :Address, :JobStatus)"	   
);
$setup->bindParam(':Name',$Name);
$setup->bindParam(':Age',$Age);
$setup->bindParam(':Contact',$Contact);
$setup->bindParam(':Email',$Email);
$setup->bindParam(':Address',$Address);
$setup->bindParam(':JobStatus',$JobStatus);
$setup->execute();


//Write Checkbox values to DB

 $setup_2 = $conn->prepare("
                  INSERT INTO 
                        TutorStudentGrade(StudentGradeLevel)
                        VALUES
                        (:Grade)");
    $setup_2->binParam(':Grade',$Grade);

foreach($_POST['StudentGradeLevel'] as $Grade) {
   
    $setup_2->execute();
                        
} 
}
echo "New records created successfully!";
}
catch(PDOException $e)
{
echo "Error:" .$e->getMessage();
}
$conn = null;
?>





line 53 in my IDE equal to line 50 here
Was This Post Helpful? 0
  • +
  • -

#34 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2389
  • View blog
  • Posts: 9,610
  • Joined: 03-December 12

Re: Can't insert multiple checkbox values to Mysql table

Posted 08 February 2018 - 06:49 PM

Read the error
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3