I am working on a project, and I am getting undefined errors for $host, $dbname, $user, and $pass.
But the errors only occur when those are inside of the dbConnect() function.
Here's the code (upload.php):
<?php error_reporting(E_ALL); require('config.php'); $filename = htmlentities($_FILES['file']['name']); $tmpname = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; $filetype = $_FILES['file']['type']; function dbConnect() { try { global $dbcon; $dbcon = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); } catch (PDOException $e) { echo $e->getMessage(); } } if (dbConnect()) { print('worked'); } config.php:
<?php global $host, $user, $pass, $dbname; $host = "localhost"; // MySQL Hostname $user = "root"; // MySQL User $pass = "mypass"; // MySQL Password $dbname = "files";