Jump to content

[SOLVED] Creating Database with form and php


big-dog1965

Recommended Posts

Im getting an error with this can someone tell me the problem

The htm form

<form method="post" action="createdb.php"> 
User Name: <input type="text" name="user" /> 
Password: <input type="password" name="pass" /> 
Database Name: <input type="text" name="dbname" /> 
<input type="submit" /> 
</form>

This is the php

<?php
$con = mysql_connect("localhost",$_POST["user"],$_POST["pass"]);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE".$_POST["dbname"],$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?>

This is the error

Error creating database: 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 'DATABASEmydb' at line 1

Archived

This topic is now archived and is closed to further replies.

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