Hi All,
This is my first project on PHP and first time encounter this bug which really can’t solve after struggle one day.
Can any expert and kind soul here advise how to resolve this error please? My PHP version is 5.6.
Thank you so much,
After I submit my form, it shows below error
Fatal error: Call to a member function prepare() on null in on line 28
My DB connection coding is
[code]
<?php
$DSN= ‘mysql:host = localhost; dbname=cms4.2.1’;
$ConnectingDB = new PDO($DSN, ‘root’, ”);
?>
Category page that shows line 28 got error on the POD function “prepare”
[code]
if(empty($Category))
{
$_SESSION[“ErrorMessage”] = “All fields must be filled out”;
Redirect_to(“Categories.php”);
} elseif (strlen($Category)<3) {
$_SESSION[“ErrorMessage”] = “Category Title should be greater than 3 characters”;
Redirect_to(“Categories.php”);
} elseif (strlen($Category)>49) {
$_SESSION[“ErrorMessage”] = “Category Title should be less than 50 characters”;
Redirect_to(“Categories.php”);
} else {
global $ConnectingDB;
$sql = “INSERT INTO category(title,author,datetime)”;
$sql .=”VALUES(:categoryName,:adminName,:dateTime)”;
$stmt = $ConnectingDB->prepare($sql); // – > means PDO object rotation – Line 28
$stmt->bindValue(‘:categoryName’,$Category);
$stmt->bindValue(‘:adminName’,$Admin);
$stmt->bindValue(‘:dateTime’,$DateTime);
$Execute=$stmt->execute();
Please help me as I have no one to asks already besides this forum.
Thank you so much.
__Edited to add `[code]…[/code]