winmastergames Posted December 30, 2007 Share Posted December 30, 2007 Well not that long ago i wanted that MYSQL script to insert the SQL file thats done but to be a pain i took it one step forward and Used the GET Method so the user inputs dbame, host, username and password into a form and sends it to the script that will insert the sql script into the database thats made which is typing into the form I thought i have done it all right but it doesnt exactly work it inserts a table called $dbname see the php script below to know what it is <?php //GET options $host = $_GET["host"]; $username = $_GET["username"]; $password = $_GET["password"]; $dbname = $_GET["dbname"]; // database connection $db=mysql_connect("$host","$username","$password"); //create database $query='CREATE DATABASE $dbname'; $result=mysql_query($query)or die('<center><b>Database exists please delete database or change database name</b></center>'); //select database mysql_select_db("$dbname",$db); $sql = 'CREATE TABLE `serverstatus` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(255) collate latin1_general_ci NOT NULL, `url` varchar(255) collate latin1_general_ci NOT NULL, `description` text collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) )'; //query database mysql_query( $sql, $db ); $result5="SHOW COLUMNS FROM zones"; $result6=mysql_query($result5)or die('error on show columns'); while($row=mysql_fetch_row($result6)){ for($i=0; $i<count($row); $i++){ echo "<br>$row[$i] <br>"; } } mysql_close($db); ?> I thought that would work?? EDIT: heres the Form HTML code <FORM action="makedb-insert-data.php" method="get"> <P> <LABEL for="username">DataBase Username: </LABEL> <INPUT type="text" id="username"><BR> <LABEL for="password">DataBase Password: </LABEL> <INPUT type="text" id="password"><BR> <LABEL for="host">DataBase Host: </LABEL> <INPUT type="text" id="host"><BR> <LABEL for="dbname">DataBase Name: </LABEL> <INPUT type="text" id="dbname"><BR> <INPUT type="submit" value="Send"> <INPUT type="reset"> </P> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/ Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 you havent named any input fields m8.... Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425657 Share on other sites More sharing options...
winmastergames Posted December 30, 2007 Author Share Posted December 30, 2007 I thought they were Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425659 Share on other sites More sharing options...
winmastergames Posted December 30, 2007 Author Share Posted December 30, 2007 Ok just fixed it but it still makes a database with the name $dbname ???? Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425663 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 post your current form Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425672 Share on other sites More sharing options...
winmastergames Posted December 30, 2007 Author Share Posted December 30, 2007 Ok here it is <FORM action="makedb-insert-data.php" method="get"> <P> Database Host: <input type="text" name="host" /><BR> Database User: <input type="text" name="username" /><BR> Database Pass: <input type="text" name="password" /><BR> Database Name: <input type="text" name="dbname" /><BR> <INPUT type="submit" value="Send"> <INPUT type="reset"> </P> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425676 Share on other sites More sharing options...
winmastergames Posted December 30, 2007 Author Share Posted December 30, 2007 Also it doesnt insert the SQL data or make the right name BUT it connect's fine? Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425677 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 fully working trie.... <?php $host=addslashes(trim($_POST["host"])); $username=addslashes(trim($_POST["username"])); $password=addslashes(trim($_POST["password"])); $dbname=addslashes(trim($_POST["dbname"])); if(isset($_POST['submit'])){ // database connection $db=mysql_connect("$host","$username","$password"); //create database $query="CREATE DATABASE $dbname"; $result=mysql_query($query)or die('<center><b>Database exists please delete database or change database name</b></center>'); //select database mysql_select_db($dbname,$db); $sql = 'CREATE TABLE `serverstatus` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(255) collate latin1_general_ci NOT NULL, `url` varchar(255) collate latin1_general_ci NOT NULL, `description` text collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) )'; //query database mysql_query($sql,$db); mysql_close($db); } ?> <FORM action=" " method="POST"> <P> Database Host: <input type="text" name="host" /><BR> Database User: <input type="text" name="username" /><BR> Database Pass: <input type="text" name="password" /><BR> Database Name: <input type="text" name="dbname" /><BR> <INPUT name="submit" type="submit" value="Send"> <INPUT type="reset"> </P> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425693 Share on other sites More sharing options...
winmastergames Posted December 30, 2007 Author Share Posted December 30, 2007 Thanks it works now wonder what was wrong before?? Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425704 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 loads changed all get to post then added addslashes and trim and a isset and submit and a name for the submit.... and i found double quotes naughty person lol. whale ur tiering me out lol...... what next tell me waiting for your command? Quote Link to comment https://forums.phpfreaks.com/topic/83671-solved-taking-it-one-step-further/#findComment-425708 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.