I am trying to do an insert to my MySQL database with PHP PDO. There is my connection code on my connection file located at ../Info/Connection.php
<?php
$user = "InsertDB";
$pass = "Passwword123";
$dbh = new PDO('mysql:host=localhost;dbname=SQL10', $user, $pass);
?>
I am using an insert on another page. Here is the insert code on my form page at ../Events/Add.php
<?php
include "../Info/Connection.php";
?>
<html>
<head>
<meta charset="UTF_8">
</head>
<body>
<H1>Add Event</H1>
Add An Event.<br/ >
<hr />
<?php
if (!empty($_POST["Submit"])) {
$EventDate = $_POST['YYYYOfEvent']."-".$_POST['MMOfEvent']."-".$_POST['DDOfEvent'];
$TodayDate = date("Y-m-d");
$statement = $pdo->prepare('INSERT INTO techdates (DateOfEvent, Event, Assigned, Status, DateOfUpdate) VALUES (:dateofevent, :event, :assigned, :status, :dateofupdate)');
$statement->execute([
'dateofevent' => $EventDate,
'event' => $_POST['Event'],
'assigned' => $_POST['Assigned'],
'status' => $_POST['Status'],
'dateofupdate' => $TodayDate
]);
}
else {
}
?>
</body>
</html>
For the prepare line I am getting the following error:
Fatal Error: Uncaught Error: Call to a member function prepare() on null in File.php:17 Stack trace: #0 {main} thrown in File.php on line 17.
I have never seen this error before but this is preventing the insert. Do I have syntax issue somewhere? I am pretty sure I have connection to my DB without an issue. What do I seem to be missing.
EDIT: I have copied the connection information to the Add.php page and now it works. I am wondering if my include statement is missing something. It is as follows.
<? php
include "../Info/Connection.php";
global $pdo;
?>
EDIT2: Added the updated actual code.