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
    what is your DB Name? – noobie-php Mar 13 '14 at 17:29
  • The database name is userdatabase – user3416605 Mar 13 '14 at 17:30
  • try mysql_query("SELECT * FROM userdatabase.users WHERE username='$user'") – noobie-php Mar 13 '14 at 17:30
  • so shouldnt it be `userdatabase.users` – Fallenreaper Mar 13 '14 at 17:30
  • As a sidenote, the other option is that in your mysql init functionality, you are opening the wrong database or DONT have one opened at all. So it doesnt find the users table. – Fallenreaper Mar 13 '14 at 17:31
  • i dont know why you got Upvote for this? – noobie-php Mar 13 '14 at 17:32
  • Obligatory Suggestion, [**Don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Lawrence Cherone Mar 13 '14 at 17:33
  • I am also facing the same issue, can any body help me [question](https://stackoverflow.com/questions/60008298/how-to-access-data-from-table-using-php-mysql) – Abhishek Pratap Singh Feb 01 '20 at 04:09
  • I am also facing the same issue, can any body help me [question](https://stackoverflow.com/questions/60008298/how-to-access-data-from-table-using-php-mysql) – Abhishek Pratap Singh Feb 01 '20 at 04:10
  • I am also facing the same issue, can any body help me [question](https://stackoverflow.com/questions/60008298/how-to-access-data-from-table-using-php-mysql) – Abhishek Pratap Singh Feb 01 '20 at 04:11

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,419
  • 7
  • 38
  • 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,042
  • 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