0
$check = mysql_query("
SELECT username 
FROM users 
WHERE username = '$usercheck'
");

Above is my code, the problem I have is I can't create the table stonecrg_password.users because of the period.

How can I change the code above so that it'll only show stonecrg_users. Even if I change the code to:

$check = mysql_query("
SELECT username 
FROM stonecrg_users 
WHERE username = '$usercheck'
");

It will still show stonecrg_password.stonecrg_users.

Jared Farrish
  • 48,585
  • 17
  • 95
  • 104

1 Answers1

1

Your question is a bit unclear for me, but as far as I know you can use ` to mark tables, columns and database in a mysql query. For instance:

SELECT `<tablename>`.`<columnname>`
FROM `<dbname>`.`<tablename>`
WHERE `<tablename>`.`<columnname>` = '$usercheck'

And if your problem is Database selection, then use following before query.

//$connection is your connection handler
mysql_select_db('<dbname>',$connection);
Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
Shoogle
  • 206
  • 1
  • 13
  • [Backticks (**`**)](http://stackoverflow.com/questions/261455/using-backticks-around-field-names) are typically used like that, but I don't see how that can solve the problem the OP is describing. The second part, though, I suspect may have something to do with it. – Jared Farrish Dec 18 '11 at 09:34
  • True! I guess we need to wait till the user provides clarity – Shoogle Dec 18 '11 at 09:36
  • Also, I think if you put `tablename`s on each field in the `SELECT` statement, MySQL will complain/fail. You only need it for disambiguation, I believe. – Jared Farrish Dec 18 '11 at 09:37
  • stonecrg_password is a database. My question is how can I fix the code so that it doesnt ask for a table named 'stonecrg_password.user' and i can just use 'stonecrg_user' Because at the moment i dont have the db 'stonecrg_password.user' created, because of the period in there i cant create it so how can i change it so it would instead ask for 'stonecrg_user' – user1101495 Dec 18 '11 at 09:47
  • From what I understand stonecrg_user is a table name. what is the database name in which stonecrg_user table is created? – Shoogle Dec 18 '11 at 09:52
  • Go here, http://stonecraftserver.com/Untitled-3.php type anything for username and password, so it returns the error "Table 'stonecrg_password.user' doesn't exist" I cant create that table because it has a period after password, so my question is how can I change the code above, so instead of asking for the table with .user it would just be 'stonecrg_user' – user1101495 Dec 18 '11 at 09:58
  • it would be great if you can post here the connection string and a line of your query together to get the idea – Shoogle Dec 18 '11 at 10:04
  • How could I get that lol? Simplify it for me? im pretty new at this – user1101495 Dec 18 '11 at 10:04
  • well if you are new and you dont mind sharing, Share the code of stonecraftserver.com/Untitled-3.php here. – Shoogle Dec 18 '11 at 10:08