Jump to content

Create database in mysql error.


nick_whitmarsh

Recommended Posts

Hey guys really new at this, blah blah blah.

 

Anyway I am trying to run a mini form that alows the user to enter a new database. It gets a blank page when I try this, however i tried all the lines of code and the error I believe lies in this line of code below :-

 

$rs1 = @mysql_create_db( $_REQUEST['db'] )

 

if anyone could help me with this i would be grateful.

 

Cheers guys.

 

Nick

Link to comment
Share on other sites

Yeah sorry. Nah the semi-colon didnt fix anything.

 

The problem  is that I just get a blank page, guess I should have said that  ::) sorry.

 

Anyway the code is :-

 

<?php $user = "nick";

$conn = @mysql_connect( "localhost",$user,"reading")
or die ("Sorry - could not connect to MySQL");

$rs1 = @mysql_create_db( $_REQUEST['db'] );

$rs2 = @mysql_list_dbs ( $conn );
for( $row = 0; $row < mysql_num_rows ( $rs2 ); $row++ )
{ $list .= mysql_tablename( $rs2, $row) . " | "; }
?>
<html><head><title>Creating Databases</title></head>
<body>
<form action = "<?php echo( $_SERVER['PHP_SELF'] ); ?>"
method="post">Current databases: <?php echo( $list ); ?>
<hr>Name:<input type = "text" name = "db">
<input type = "submit" value = "Create database">
</form></body></html>

 

As I said I went through the code and it all works until I used the line of code i already stated.

 

cheers

 

Nick

Link to comment
Share on other sites

As jcbarr said, I suggest using

mysql_connect ("localhost","$user","$password")
$soru = 'CREATE DATABASE '.$_REQUEST['db'];
mysql_query($soru);

 

since I have heard mysql_create_db is deprecated.

 

If you hard code the database name in, will it create it?  The mysql name does have access to create databases, correct? 

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.