PHP : Using a variable to hold a table name, and using that variable in queries

database, mysql, php, variables

Solution

$query = "INSERT INTO `" . $mysql_tb . "`
VALUES ('".$studno."','".$firstname."','".$lastname."')";

Problem

I am currently learning PHP, and I'm working on a Registration Form. Somewhere in my code I have these statements ``` $query = "SELECT `stud_no` FROM `tb_registered_users` WHERE `stud_no`='$studno'"; ``` and ``` $query = "INSERT INTO `tb_registered_users` VALUES ('".$studno."','".$firstname."','".$lastname."')"; ``` but instead I want to declare this variable and use it in the queries mentioned above ``` $mysql_tb = 'tb_registered_users'; ``` So what is the correct syntax for this?

Original source

Related problems