hyster Posted February 23, 2011 Share Posted February 23, 2011 im trying to create a table for a site admin. bsicaly all he has to do is fill out a form and the values of the form are turned into the table name. im using a .sql file as a template but to create the table i need the php genarated table name to be inserted into the .sql file. <?php include("config.php"); $con details $tbl_name = "static_name_for_now"; if (mysql_query("seat_plan.sql")) { echo "success"; } else{ echo "fail"; } ?> sql file snippet INSERT INTO `<?php $tbl_name ?>` VALUES('A', 1, 0, 'Y'); also tried INSERT INTO `<?php echo $tbl_name ?>` VALUES('A', 1, 0, 'Y'); thanks Link to comment https://forums.phpfreaks.com/topic/228622-php-var-inside-filesql/ Share on other sites More sharing options...
Muddy_Funster Posted February 23, 2011 Share Posted February 23, 2011 I'm not really sure on what you are doing here, but I think it's likely failing because you can't just call an external file as a variable for mysql_query(), you will need to load it first, or not just use it. Link to comment https://forums.phpfreaks.com/topic/228622-php-var-inside-filesql/#findComment-1178771 Share on other sites More sharing options...
hyster Posted February 23, 2011 Author Share Posted February 23, 2011 i can load the sql file now and it runs ok apart from there is no table name which i want to use as $var table.sql file snippet INSERT INTO `<?php echo $tbl_name?>` VALUES('A', 1, 0, 'Y'); INSERT INTO `<?php echo $tbl_name?>` VALUES('A', 2, 0, 'Y'); INSERT INTO `<?php echo $tbl_name?>` VALUES('A', 3, 0,'Y'); INSERT INTO `<?php echo $tbl_name?>` VALUES('A', 4, 0,'Y'); atm im getting INSERT INTO `` VALUES('A', 1, 0,'Y'); INSERT INTO `` VALUES('A', 2, 0,'Y'); INSERT INTO `` VALUES('A', 3, 0,'Y'); INSERT INTO `` VALUES('A', 4, 0,'Y'); Link to comment https://forums.phpfreaks.com/topic/228622-php-var-inside-filesql/#findComment-1178778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.