giba Posted February 8, 2007 Share Posted February 8, 2007 Hi, I am having a trouble about creating a database directly by form using a variable within CREATE DATABASE line: the form: <form action="create_database.php" method="post"> Type a name to your database: <br /> <input type="text" name="database_name" size="80"><br /> <input type="Submit" value="Create New Database"> the php script: <?php $database="$_POST['database_name']; $con = mysql_connect('server', 'user', 'password'); if (!$con) { die('Connection to database failed: ' . mysql_error()); } $sql = 'CREATE DATABASE'.($database); // I've tried all combination on this line and nothing works! if (mysql_query($sql)) { echo "Database ".$banco." created!\n"; } else { echo 'None database created: ' . mysql_error() . "\n"; } ?> I would like some friend help me! Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/ Share on other sites More sharing options...
only one Posted February 8, 2007 Share Posted February 8, 2007 are you with a webhost that only allows up to 1 database, theyl usually have the functions blocked out so you cant make a new database Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180165 Share on other sites More sharing options...
giba Posted February 8, 2007 Author Share Posted February 8, 2007 No, the trouble is not the number of databases allowed! I am trying to build an application to create a database by form, because normally people are taught to create databases directly by using mysql console or direct php script, with a value or variable pre-defined. My will is to create a script just with a form that one could enter a name. For example: In a school every teacher is allowed to create a personal account. Then that is encouraged to enter an account name by a form. So, the new database name is that, the account's name. The trouble however is: what's wrong with the above code? Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180214 Share on other sites More sharing options...
giba Posted February 8, 2007 Author Share Posted February 8, 2007 Hi, I am having a trouble about creating a database directly by form using a variable within CREATE DATABASE line: the form: <form action="create_database.php" method="post"> Type a name to your database: <br /> <input type="text" name="database_name" size="80"><br /> <input type="Submit" value="Create New Database"> the php script: <?php $database="$_POST['database_name']; $con = mysql_connect('server', 'user', 'password'); if (!$con) { die('Connection to database failed: ' . mysql_error()); } $sql = 'CREATE DATABASE'.($database); // I've tried all combination on this line and nothing works! if (mysql_query($sql)) { echo "Database ".$database." created!\n"; } else { echo 'None database created: ' . mysql_error() . "\n"; } ?> I would like some friend help me! Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180220 Share on other sites More sharing options...
artacus Posted February 8, 2007 Share Posted February 8, 2007 For starters you need a space after DATABASE. Your query would look like this CREATE DATABASEfoobar Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180228 Share on other sites More sharing options...
FrobinRobin Posted February 9, 2007 Share Posted February 9, 2007 To solve my own noob problems I usually echo the query on the web page before executing it. Then I copyNpaste the query into PHPMYADMIN to see if it works A great way to find those school boy errors as PHPMYADMIN will give you a clue as to whats wrong. Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180588 Share on other sites More sharing options...
frozen.cell Posted February 9, 2007 Share Posted February 9, 2007 Have u try to use mysql_create_db([database_name]) ? Maybe it will sold ur problem. Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180595 Share on other sites More sharing options...
giba Posted February 9, 2007 Author Share Posted February 9, 2007 I would like to thank you, artacus. In fact a concatenation space after DATABASE was required. wrong: $sql = 'CREATE DATABASE'.$database; // is equal to CREATE DATABASE$database - it can't work! Correct: $sql = 'CREATE DATABASE '.($database); // is equal to CREATE DATABASE $database - it can work!! Thanks! Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180819 Share on other sites More sharing options...
giba Posted February 9, 2007 Author Share Posted February 9, 2007 SOLVED Link to comment https://forums.phpfreaks.com/topic/37660-solved-i-cant-create-a-database-using-a-form-with-mysql_query/#findComment-180824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.