Problem with mysql_select_db()

Problem with mysql_select_db()

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.
offline
  • PHP developer
  • 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...



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 Smile
sorry is not explained very good, but still try to understand the point

offline
  • Peca  Male
  • 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...

offline
  • igor86  Male
  • Stručni saradnik
    Web programiranje
  • Pridružio: 24 Maj 2006
  • Poruke: 1633

Give us a
print $queryCreateTable;
before query

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) );

Ko je trenutno na forumu
 

Ukupno su 1123 korisnika na forumu :: 34 registrovanih, 5 sakrivenih i 1084 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: A.R.Chafee.Jr., babaroga, Bahuss, Ben Roj, comi_pfc, dane007, DejanCG, DH, dolinalima, Excalibur13, FileFinder, havoc995, Kubovac, kvcali, lcc, leonard, ljuba, mackenzie, madza, Metanoja, MiG-29M2, milenko crazy north, MiroslavD, mrvica78, oldtimer, panzerwaffe, Parker, pein, robertino, Rogan33, vargas, vathra, virked, Yellow Pinky