Nathaniel Pantilanan Nathaniel Pantilanan - 1 month ago 7
MySQL Question

fatal error in query() error in mysql

im new in programming and this keep showing up.

here is my connect.php

<?php

$username = "root";
$password = "";
$db = "app";

// Create connection

$conn = mysqli_connect("localhost", $username, $password, $db);

if (!@$conn) {
die ("Unable to Connect!");
}
else {
echo "Connected!";
}

?>


and the error keep showing in this code(index.php)
the error says


Fatal error: Uncaught Error: Call to a member function query() on string in C:\xampp\htdocs\nath\index.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\nath\index.php on line 5


<?php
error_reporting(E_ALL);
require 'db/connect.php';

if ($update = $db->query("UPDATE people SET created = NOW()")) {

}


?>

Answer
<?php
error_reporting(E_ALL);
require 'db/connect.php'; 

if ($update = $conn->query("UPDATE people SET created = NOW()")) {

 }


 ?>

$update = $conn->query because your connection is $conn not $db