Anne De Graaff
Anne De Graaff

Reputation: 13

I have a php error. But I don't understand why

I have a problem in my code. I'm trying to make a private chat. I am using php and mysql. But now I have this error: "Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Table 'b7_19757973_4hfbroup.asdfannedegraaff' doesn't exist" And I know that it means that the table does not exist. But I use this code to look if the table exist:

$query = mysqli_query($con, "SELECT * FROM `".$_SESSION['senderreceiver']."`");
if(!$query)
   echo "The s does not exists";
$query2 = mysqli_query($con, "SELECT * FROM `".$_SESSION['receiversender']."`");
if(!$query2)
   echo "The f does not exists";

But I still get the error, How can I fix this?

btw the session are made like this:

$sender = $_SESSION['username']; 
$receiver = $_POST["name"];
$senderreceiver = $sender . $receiver;
$receiversender = $receiver . $sender;

$_SESSION['senderreceiver'] = $senderreceiver;
$_SESSION['receiversender'] = $receiversender;

I'm sorry for my bad english and for my bad explanation. But I hope you can help me..

Upvotes: 0

Views: 1165

Answers (1)

If a Table does not exist, MYSQLI will ALWAYS throw that Error.

Try instead SHOW TABLES LIKE 'tablename';

But one further concern: Do not save Database table names inside the Session. It's bad practice and in 99% of the cases not needed

Upvotes: 2

Related Questions