0

I am trying to set up a simple log in sign up system, but when I try to run this query:

$query = mysql_query("SELECT * FROM users WHERE username='$user'") or die(mysql_error());

I get the error:

Table 'users.users' doesn't exist

Is there any way I could fix this? I know I am putting in the right table name.

Thank you for your help!

user3416605
  • 79
  • 1
  • 6

2 Answers2

1

Try this one:

$query = mysql_query("SELECT * FROM `userdatabase.users` WHERE username='$user'") or die(mysql_error());

From your example it seems that you have chosen different database than userdatabase, because the table is not found, so if you're dealing with tables from marked database, it's good way to change working database to userdatabase and then execute queries without namespace

See mysql_select_db (just mentioning mysql extension because you're using it) for database changing porpose, though get rid of mysql extension

Community
  • 1
  • 1
nanobash
  • 5,293
  • 7
  • 34
  • 56
  • 1
    I didnt downvote, but i find this gets around the idea of using the correct database to begin with. You are accessing it from global, whereas i feel he should just adjust the scope of which database that session is looking at – Fallenreaper Mar 13 '14 at 17:33
  • @Fallenreaper It's good to choose database on which you're working, though this query should work just fine :) – nanobash Mar 13 '14 at 17:35
  • 1
    i concur. Though being stackoverflow, should i give you points for a working answer, or the best answer? *ponders* Here, have an upvote. – Fallenreaper Mar 13 '14 at 17:38
0

Aber connecting to your database server, you need to select your database.

mysql_select_database('databasename');

Not sure if that is the correct functionname

Pinki
  • 1,043
  • 9
  • 17
  • this is the answer i would choose personally. You are looking for `mysql_select_db('userdatabase');` though. http://www.php.net/mysql_select_db – Fallenreaper Mar 13 '14 at 17:36