big-dog1965 Posted February 11, 2009 Share Posted February 11, 2009 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 Link to comment https://forums.phpfreaks.com/topic/144705-solved-creating-database-with-form-and-php/ Share on other sites More sharing options...
gevans Posted February 11, 2009 Share Posted February 11, 2009 You need a space before the database name "CREATE DATABASE".$_POST["dbname"] should be; "CREATE DATABASE ".$_POST["dbname"] Link to comment https://forums.phpfreaks.com/topic/144705-solved-creating-database-with-form-and-php/#findComment-759331 Share on other sites More sharing options...
big-dog1965 Posted February 11, 2009 Author Share Posted February 11, 2009 that got rid of that error but now I get cant creat db. I sent a ticket to my host to see why I dont have the priv to create DB without going into cp Link to comment https://forums.phpfreaks.com/topic/144705-solved-creating-database-with-form-and-php/#findComment-759386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.