Jump to content

[SOLVED] Taking it one step further


winmastergames

Recommended Posts

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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.