Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP PDO Prepared Insert Query. Problem with value not being passed
    primarykey
    data
    text
    <p>I am using PDO to do prepared queries in php with MySQL. The query executes with no errors but one parameter does not pass it's value properly. It come sup as a blank field, but not NULL. It's really weird as it seems that I entered the code the same as the others which of course work fine. Really frustrating.</p> <pre><code>$f_name = $_POST['f_name']; $l_name = $_POST['l_name']; $email = $_POST['email']; $pass = $_POST['pass']; $address1 = $_POST['address_1']; $address2 = $_POST['address_2']; $suburb = $_POST['suburb']; $city = $_POST['city']; $country = $_POST['country']; $phone = $_POST['phone']; include('db_connect.php'); $stmt = $db_connection-&gt;prepare('INSERT INTO tblUser (userID,fName, lName, email, password, addressLine1, suburb, city, country, phone) VALUES( NULL, :f_name, :l_name, :email, :pass, :address1, :suburb, :city, :country, :phone)'); $stmt-&gt;bindParam(':f_name', $f_name, PDO::PARAM_STR); $stmt-&gt;bindParam(':l_name', $l_name, PDO::PARAM_STR); $stmt-&gt;bindParam(':email', $email, PDO::PARAM_STR); $stmt-&gt;bindParam(':pass', $pass, PDO::PARAM_STR); $stmt-&gt;bindParam(':address1', $address1, PDO::PARAM_STR); //$stmt-&gt;bindParam(':address2', $address2, PDO::PARAM_STR); $stmt-&gt;bindParam(':suburb', $suburb, PDO::PARAM_STR); $stmt-&gt;bindParam(':city', $city, PDO::PARAM_STR); $stmt-&gt;bindParam(':country', $country, PDO::PARAM_STR); $stmt-&gt;bindParam(':phone', $phone, PDO::PARAM_STR); try { $stmt-&gt;execute(); print_r($stmt); $result = $stmt-&gt;fetchAll(); } catch (Exception $e) { echo $e; } </code></pre> <p>The output of print_r($_POST); is: Array ( [email] => test@test.com [pass] => pass [pass_confirm] => pass [f_name] => fefs [l_name] => sfasafs [address_1] => sfafsa [address_2] => dsfsafsaf [suburb] => dffdsa [city] => dsffdf [country] => sfaafdsa [phone] => fsaafssaf [submit] => Register )</p> <p>The problem is that the database is populated with a new record but the password field is a blank. I removed hashing to simplify things.</p> <p>Here is the SQL of the user table:</p> <pre><code>CREATE TABLE IF NOT EXISTS `tbluser` ( `userID` int(11) NOT NULL AUTO_INCREMENT, `password` varchar(40) NOT NULL, `email` varchar(60) NOT NULL, `addressLine1` varchar(30) DEFAULT NULL, `addressLine2` varchar(30) DEFAULT NULL, `suburb` varchar(30) DEFAULT NULL, `city` varchar(30) DEFAULT NULL, `country` varchar(40) DEFAULT NULL, `phone` varchar(25) DEFAULT NULL, `fName` varchar(30) DEFAULT NULL, `lName` varchar(30) NOT NULL, `admin` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`userID`), UNIQUE KEY `email` (`email`), UNIQUE KEY `email_3` (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload