I am trying to figure out why my PDO methods keep returning null values. Everything seems correct, from the prepare to the execute.
i.e. "Fatal error: Call to a member function prepare() on null in /blah/register.php on line 5"
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); if ($email === ''){ unset($email); }else{ $query = $mysqli->prepare('SELECT email FROM `Members` WHERE email=:input_email'); $query->execute(array(':input_email' => $email)); foreach ($query as $row) { echo $row['email'] . "<br />"; } var_dump($query); die(); } This code should echo all values, and then kill the rest of the script.
db connect:
$db = new PDO('mysql:host=hostname;dbname=dbname;charset=utf8', 'dbuser', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); if ($db->connect_errno) { echo "<b>Sorry, this website is experiencing problems. </b>"; exit; }
SELECT email FROMMembers` WHERE email=:input_email` you always get$email