Jump to content

php var inside file.sql


hyster

Recommended Posts

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

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');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.