I Need help to create tables from .sql file using a submit button. I have written a Mysql code for the tables on a .sql file. but now i want that file to be executed to create those tables on a database which is configured on config.php file when Install Now button is clicked on install.php. can anyone help me with it? currently i am here : Config.php <?php include 'config.php'; $conn=@mysql_connect($DBhost,$DBuser,$DBpass) or die(mysql_error()); @mysql_select_db("$DBName") or die(mysql_error()); $queryfile = "tables.sql" ?> PHP: Install.php <?php $DBhost = "localhost"; //Your database host you can usually $DBuser = "Your DB"; //Your Database user name here $DBpass = "Database PW"; //Your Database pw here $DBName = "DBName"; //Your Database name here $user = admin; //the username you want to log in with change this! $pass = admin; //the pass you want to log in with change this! ?> PHP: tables.sql CREATE TABLE `aff` ( `id` int(15) NOT NULL auto_increment, `sitename` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', `clicks` int(15) NOT NULL default '0', `button` varchar(255) NOT NULL default '', `active` char(3) NOT NULL default 'no', PRIMARY KEY (`id`) ) ENGINE=MyISAM; PHP: actually i am creating an affiliate system script but i am new at php , this is my first project. now on install.php , i cant figure out how to execute the queryfile when someone click on install now button(button's code isnt written yet). i will be really glad if someone could help me out..
why not put the query(contents of .sql file) in a php file and run mysql_query($query) to execute it?
Put the content of your sql right inside a mysql query from php: mysql_query("CREATE TABLE..."); PHP:
both of you gave me suggestions which i am trying to do. but u see above.. i am asking how to put the content of sql file in $query and execute it using submit button. and @linkstraffic , i dont know how to convert mysql queries in php format , i told u i am new. Updated !!! hey both of u , i solved my problem my self , i used google , i searched for how to insert info in sql db using submit button , and i had to browse loads of sites , but finally , on one site , it explained how to insert tables using php , i read it , use it to convert my mysql query to php format , and read something on another website about submit button , and read on 3rd website about fopen syntax , i combined them all , and made a code that actually works :d !! check it out : <?php include 'config.php'; if(isset($_POST['btnSign'])) { $conn=@mysql_connect($DBhost,$DBuser,$DBpass) or die(mysql_error()); @mysql_select_db("$DBName") or die(mysql_error()); $queryFile = 'sql.sql'; $fp = fopen($queryFile, 'r'); $query = fread($fp, filesize($queryFile)); fclose($fp); $result = mysql_query($query); } ?> <html><head> </head> <body> <form method="post" name="guestform"> <input name="btnSign" type="submit" id="btnSign" value="Install Tables"> </form> </body></html> PHP: and in sql.sql , i wrote the php format sql query first , but i couldnt manage to convert the sql to php properly , it messsed up the properties of tables , so i tried original sql query on sql.sql file and it worked perfectly fine. thanks everyone for reading my thread..i will post more later if i face any other problem .