title: Trying to handle a checkbox value as a boolean for input into a database
body: <p>Trying to handle the input from a check box as a boolean so that I can input the value amongst others into a database. The value is "mailingList" and i thought i had cracked it but it now just returns a pre defined error in my "catch" which should be unrelated. Below is the $_Post from the form</p>
  
  <pre><code>&lt;?php
    if (isset($_POST['register'])) {
       $email = trim($_POST['email']);
       $password = trim($_POST['pwd']);
       $retyped = trim($_POST['conf_pwd']);
       $firstname = trim($_POST['fname']);
       $lastname = trim($_POST['lname']);
       $company = trim($_POST['company']);
       $mailinglist = trim($_POST['mailingListCheckbox']);
       require_once('./includes/register_user_pdo.inc.php');
    }
  ?&gt;
  </code></pre>
  
  <p>then there is the related register_user_pdo.inc.php</p>
  
  <pre><code>&lt;?php
    require_once('./classes/CheckPassword.php');
    $errors = array();
    if (preg_match('/\s/', $email)) {
       $errors[] = 'Email should not contain spaces.';
    }
    if (!isset($mailingList)) {
      $mailingListValue = FALSE;
  }
  else {
      $mailingListValue = TRUE;
  }
    $checkPwd = new Ps2_CheckPassword($password, 10);
    $checkPwd-&gt;requireMixedCase();
    $checkPwd-&gt;requireNumbers(2);
    $checkPwd-&gt;requireSymbols();
    $passwordOK = $checkPwd-&gt;check();
    if (!$passwordOK) {
       $errors = array_merge($errors, $checkPwd-&gt;getErrors());
    }
    if ($password != $retyped) {
       $errors[] = "Your passwords don't match.";
    }
    if (!$errors) {
       // include the connection file
       require_once('./includes/connection.inc.php');
       $conn = dbConnect();
       // create a salt using the current timestamp
       $salt = time();
       // encrypt the password and salt with SHA1
       $pwd = sha1($password . $salt);
       // prepare SQL statement
       $sql = 'INSERT INTO users (email, salt, pwd, lastName, firstName, company, mailingList)
       VALUES (:email, :salt, :pwd, :lastName, :firstName, :company, :mailingList)';
       $stmt = $conn-&gt;prepare($sql);
       // bind parameters and insert the details into the database
       $stmt-&gt;bindParam(':email', $email, PDO::PARAM_STR);
       $stmt-&gt;bindParam(':salt', $salt, PDO::PARAM_INT);
       $stmt-&gt;bindParam(':pwd', $pwd, PDO::PARAM_STR);
       $stmt-&gt;bindParam(':lastName', $lname, PDO::PARAM_STR);
       $stmt-&gt;bindParam(':firstName', $fname, PDO::PARAM_STR);
       $stmt-&gt;bindParam(':company', $company, PDO::PARAM_STR);
       $stmt-&gt;bindParam(':mailingList', $mailingListValue, PDO::PARAM_BOOL);
       try {
           $stmt-&gt;execute();
           // check number of rows affected by previous insert
           if ($stmt-&gt;rowCount() == 1) {
              $success = "$email has been registered. You may now log in.";
           }
       }catch(PDOException $e){
          if ($e-&gt;getCode() == 23000)
              $errors[] = "Email is already in use. Please use another email address.";
          else 
              $errors[] = 'Sorry, there was a problem with the database.';
      }
    }
  ?&gt;
  </code></pre>
  
  <p>Any help would be much appreciated! Thanks in advance!</p>