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?
$query = "INSERT INTO `" . $mysql_tb . "`
VALUES ('".$studno."','".$firstname."','".$lastname."')";
<?php
$mysql_tb = 'tb_registered_users';
$query = "SELECT `stud_no` FROM `{$mysql_tb}` WHERE `stud_no`='$studno'";
$query = "INSERT INTO `{$mysql_tb}` VALUES ('".$studno."','".$firstname."','".$lastname."')";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With