GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Jul-2008, 10:50
kevin433 kevin433 is offline
New Member
 
Join Date: Jul 2008
Posts: 9
kevin433 is on a distinguished road
Question

How to create a MYSQL Database with a HTML form?


Hi,
How can i create a MYSQL Database through a HTML form?
I searched and found one, but it didn't worked for me
  #2  
Old 15-Jul-2008, 14:43
kevin433 kevin433 is offline
New Member
 
Join Date: Jul 2008
Posts: 9
kevin433 is on a distinguished road

Re: How to create a MYSQL Database with a HTML form?


Please help
  #3  
Old 15-Jul-2008, 16:23
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,141
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How to create a MYSQL Database with a HTML form?


The topic is not fully clear...

What do you mean 'create with HTML form'? HTML, alone, will NOT do it for you without some sort of back end connectivity.

Can you provide some more specific details about what is trying to be done?

EDIT:
What is this 'other form' that you found that didn't work?
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #4  
Old 15-Jul-2008, 16:27
kevin433 kevin433 is offline
New Member
 
Join Date: Jul 2008
Posts: 9
kevin433 is on a distinguished road

Re: How to create a MYSQL Database with a HTML form?


I mean, when i submit a HTMl form with a text box where i typed in "lol", it creates a MYSQL database with the name i writed in the text also "lol"

EDIT:
I didn't found it, but this is what i got:

PHP Code:

<?php
    $continued = mysql_connect("localhost","****","******"); 
    if($continued)
  { 
        echo("Connection is succeed"); 
    }
  else
  { 
        echo("Connection is fail"); 
    }
?>
<form>
Database name: 
<input type="text" name="user">
<input type="submit" value="Submit">
</form>

<?php
    $make = mysql_query("CREATE DATABASE $make");
    if($make)
  { 
        echo("Database database succeeds in making"); 
    }
  else
  { 
        echo("Database database fails in making"); 
    } 
?>

Last edited by LuciWiz : 16-Jul-2008 at 01:37. Reason: Please insert your Php code between [php] & [/php] tags
  #5  
Old 15-Jul-2008, 16:36
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,141
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How to create a MYSQL Database with a HTML form?


Ok, then assuming that the back end is available through the submit, that is a query:
Code:
CREATE DATABASE <database_name>; or, with your example: CREATE DATABASE lol;
So, with your "lol", simply build the string and pass it to the DB.

[Note that having CREATE permission is assumed]

EDIT:
Ah, I see you basically have it in place. (I jumped to reply before your EDIT was added)
Can you output what $make has after it fails, are you SURE the connection succeeded?
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #6  
Old 15-Jul-2008, 18:10
kevin433 kevin433 is offline
New Member
 
Join Date: Jul 2008
Posts: 9
kevin433 is on a distinguished road

Re: How to create a MYSQL Database with a HTML form?


When i go on the .php page it says this:
Code:
Connection is succeed Database name: "here is a text box" and here is a Submit button Database database fails in making

It says that it couldn't create a database, but i don't clicked on the Submit Button. It says it when i enter the page. And when i click on the Submit Button nothing happens, just the same is there.
  #7  
Old 15-Jul-2008, 19:02
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,141
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How to create a MYSQL Database with a HTML form?


Try to add this inside the else [where make fails]
PHP Code:

$message = 'Error check: ' . mysql_error() . "\n"; // any error(s).
die($message); 


__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #8  
Old 15-Jul-2008, 19:34
kevin433 kevin433 is offline
New Member
 
Join Date: Jul 2008
Posts: 9
kevin433 is on a distinguished road

Re: How to create a MYSQL Database with a HTML form?


Now it says this:

Error check: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

but line 1 is <?php
  #9  
Old 15-Jul-2008, 20:23
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,141
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How to create a MYSQL Database with a HTML form?


That's not the line of reference, that is from MySQL.
How are you building the string? It's either complaining about misplaced quote(s), OR it's getting a blank text field when first opened. The easiest check for the second part would be to give the field a default value.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #10  
Old 15-Jul-2008, 21:17
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,141
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How to create a MYSQL Database with a HTML form?


I see another small issue, you are passing $make to the query, but how does it know what the database name is supposed to be?

Slightly modified your code, try this example:
PHP Code:

<?php
if (!empty($_GET['user']))
{
    $continued = mysql_connect("localhost","*****","*****");
    if($continued)
    {
        echo "Connection success.<br>";
    }
    else
    {
        echo "Connection failed.<br>";
    }
    
    $db_name = $_GET['user'];
    echo "<br>==>DBname: " . $db_name . "<br>";
    
    $make = mysql_query("CREATE DATABASE $db_name");
    if($make)
    {
        echo "Database $db_name created.<br>";
    }
    else
    {
        echo "Failure creating $db_name.<br>";
        echo "Reason: " . mysql_error() . "<br>";
    }
    unset($_GET['user']);
}
else
{
    echo "No name given yet.<br>";
}
?>
<html>
<form>
Database name:
<input type="text" name="user" value="">
<input type="submit" value="Submit">
</form>
</html>
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cpanel downgrade MYSQL 4.1.X to MySQL 4.0.xx Webhosting-live Web Hosting Forum 1 01-Sep-2006 03:54
HTML Form to PHP File - Help Requested vigilantweather MySQL / PHP Forum 15 07-Aug-2006 20:22
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 04:38
[Tutorial] MySQL Basics nniehoff MySQL / PHP Forum 15 23-Mar-2003 20:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:30.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.