wrathican Posted November 15, 2006 Share Posted November 15, 2006 hi.im extremely new to coding php.i have a problem with coding my databse creation form, i want to use the variables from a form to send to a database creation script.[b]heres the code for my html form:[/b]<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>[b]and heres the code from my php script:[/b]<?php $con = mysql_connect("mysqlhostserver",$_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); ?>now i got the code from w3 and instead of the $_POST variables it had the username, password and the database name already written into the script, now i dont want this. i want to be able to enter the username, password and databse name into a form and do it from there. please help?thanks in advanced Link to comment https://forums.phpfreaks.com/topic/27325-php-and-creating-databses/ Share on other sites More sharing options...
trq Posted November 15, 2006 Share Posted November 15, 2006 [code=php:0]if (mysql_query("CREATE DATABASE ".$_POST['dbname'], $con))[/code] Link to comment https://forums.phpfreaks.com/topic/27325-php-and-creating-databses/#findComment-124936 Share on other sites More sharing options...
Cagecrawler Posted November 15, 2006 Share Posted November 15, 2006 Try this:[code]<?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);?>[/code]You will have to have already given the username permission to create new databases. Link to comment https://forums.phpfreaks.com/topic/27325-php-and-creating-databses/#findComment-124943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.