Mickeyatty Posted September 1, 2018 Share Posted September 1, 2018 Hi, I am just getting a blank page and I am unable to figure out why such a simple concept is not working. Any help would be greatly appreciated. <?php //Error Check ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); try { $conn = new PDO("mysqli:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $statement = $conn->prepare("UPDATE test SET title= ? WHERE id= ?"); $statement->bind_param('si', $title,$id); $statement->execute(); if ($statement->affected_rows >0) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } $statement->close(); ?> Quote Link to comment Share on other sites More sharing options...
benanamen Posted September 1, 2018 Share Posted September 1, 2018 (edited) You are missing the closing bracket for the try and you are missing the catch. Looks like you are mixing up Mysqli and PDO. Perhaps you should study this PDO tutorial. https://phpdelusions.net/pdo Edited September 1, 2018 by benanamen Quote Link to comment Share on other sites More sharing options...
Barand Posted September 1, 2018 Share Posted September 1, 2018 You have a PDO connection but your statement processing is using mysqli methods. Stick to PDO. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 1, 2018 Share Posted September 1, 2018 you have a php syntax error. the try/catch syntax is incomplete. you are not seeing any errors since your code never runs when there is a php syntax error. you should set the error_reporting/display_errors setting in the php.ini on your system so that php will report and display ALL the errors it detects. in most cases, you should not catch exceptions in your code (only when detecting duplicate data being inserted/updated.) you should normally let php catch and handle any exception. next, the variables being used in the connection don't appear to exist, the PDO extension doesn't have a bind_param() method (it does have a bindParam() method), the two variables you are binding don't appear to exist, and instead of binding input data,you should just supply it as an array in the execute() method call. also, if there are no affected rows, that's not a query error and using $conn->error, which isn't a PDO property anyway, won't contain any useful information. if there is a query error, an exception will be thrown and the exception handler will be executed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.