BTW you can also use sprintf function to do the same thing as show below
(PHP 4, PHP 5, PHP 7)
sprintf — Return a formatted string
$mysql_tb = 'tb_registered_users';
$query1 = sprintf("SELECT `stud_no` FROM `%s` WHERE `stud_no`='$studno'",$mysql_tb);
$query2 = sprintf("INSERT INTO `%s` VALUES ('".$studno."','".$firstname."','".$lastname."')",$mysql_tb);
Just put %s in place where you want to replace the value and then use second parameter as variable as shown in here. It works as same as function in c language and c++. You can replace multiple values also with multiple parameters. Here is php manual help
https://www.php.net/manual/en/function.sprintf.php
Hope that helps