I am new to PHP and MySQL and I am trying to use PHP Variable as name of table. But when I do that it returns :
SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '321321' at line 1
My code is :
$dbname = "321321";
require_once('authenticate.php');
$ownerID = $_SESSION["accNumber"];
if($dbname != $ownerID){
header('Location: login.php');
}
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = '***'; // Password
$db_name = 'test_database'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = 'SELECT * FROM '.$dbname.'';
$query = mysqli_query($conn, $sql);