Poslao: 25 Feb 2007 20:10
|
offline
- Pridružio: 30 Sep 2006
- Poruke: 137
|
I m making a site, something like PhpMyAdmin, that will be hosted on my server.
I have index.php with one form input ("NameOfDatabase") where the user should wrote the name of the database that wanna to create, and ofcourse a submit button, that will link to another page called detail.php.
For now that is ok because it's working.
Next thing is detail.php with the form inputs for table name and other atributs for create a table in mysql, but in the top of the page i must wrote the code for linking the database.
Here is the code
$connection = mysql_connect("localhost", "user", "pass");
this code is ok, but
mysql_select_db("$_GET['NameOfDatabase']", $connection);
the second code is my problem, ithe error says : No database selected.
I think there is a problem because the database in the second page is not defined. Any help???
|
|
|
Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
|
|
Poslao: 26 Feb 2007 02:32
|
offline
- Rastafarii
- Moderator foruma
- Pridružio: 22 Mar 2006
- Poruke: 3760
- Gde živiš: 127.0.0.1
|
You are trying to select database which doesn't exists, right?
First of all, you have to make database, and THEN select it. There is no way to select ANYTHING which doesn't exists...
Hope this helps...
|
|
|
|
Poslao: 26 Feb 2007 20:38
|
offline
- Pridružio: 30 Sep 2006
- Poruke: 137
|
i think u dont understand me and maybe i dont explain very good.
I repair that, but now i have other problem
$_GET['bracket1'] == "(";
$_GET['bracket2'] == ")";
$queryCreateTable = "create table ".$_GET['NameOfTable']." ( ".$_GET['NameOfColumn']." ".$_GET['Type']." ".$_GET['bracket1']." ".$_GET['Value']." ".$_GET['bracket2']." ".$_GET['atribut']." ".$_GET['null']." ".$_GET['default']." ".$_GET['increment'].") ";
if i type the name of the table, name of the column, name of the type of variable, value of the variable, (the rest attribut, nill, default ,increment are not important) it says:
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 ') )' at line
the error is because there is )) (two brackets) one by one
this is similar like this query "create table customer(Name varchar(32) );"
and if u notice there is two bracket one by one, and if i write it in mysql command prompt, it says that is ok, there is no error.
Damn sometimes i cant understand myself
sorry is not explained very good, but still try to understand the point
|
|
|
|
Poslao: 26 Feb 2007 20:48
|
offline
- Peca
- Glavni Administrator
- Predrag Damnjanović
- SysAdmin i programer
- Pridružio: 17 Apr 2003
- Poruke: 23211
- Gde živiš: Niš
|
try
mysql_select_db($_GET['NameOfDatabase'], $connection);
but, this can be security problem, because someone can simply select table that should not be selected...
|
|
|
|
Poslao: 26 Feb 2007 21:13
|
offline
- igor86
- Stručni saradnik
Web programiranje
- Pridružio: 24 Maj 2006
- Poruke: 1633
|
Give us a
print $queryCreateTable;
before query
|
|
|
|
Poslao: 28 Feb 2007 17:30
|
offline
- Pridružio: 30 Sep 2006
- Poruke: 137
|
Peca ::try
mysql_select_db($_GET['NameOfDatabase'], $connection);
but, this can be security problem, because someone can simply select table that should not be selected...
i have that code posted in my first post.
But why security problem? He cant select a table that he doesnt created.
igor86 ::Give us a
print $queryCreateTable;
before query
i dont understand u....if u mean on the query for creating the table in mysql here is it.
create table customer(Name varchar(32) );
|
|
|
|