0

I have a mysql table for my users' username, password, etc. This code is part of my login.php file. It used to work fine but then it puked:

Note: TABLE is defined in a seperate MYSQL_CONFIG.inc.php file.

$table = mysql_query("SELECT * FROM " . TABLE . " WHERE username='$user'") or die('query');
$data = mysql_fetch_array($table) or die('fetch array');

I can't seem to figure out why this isn't working. I have another page, member.php, in which the user can change their username, password, email, etc. I fully debugged that, but when I added a link to that page in my navbar, the login page puked. It makes no sense to me. Anyone have any ideas?

I also get no error messages. I just get a blank page when I load login.php

  • Table may be a predefined constant, so you must change it and try with other name. – samayo Jun 02 '13 at 19:45
  • you are making errors die then how can you see errors ...remove those statements – pinkpanther Jun 02 '13 at 19:46
  • 3
    Off topic, but please be aware that the `mysql_xxx()` functions are considered obsolete and are deprecated. Please consider swapping them in your code for the PDO library. – Spudley Jun 02 '13 at 19:46
  • Define *puked*. Also, never ever ever [ever use mysql_*](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – pilsetnieks Jun 02 '13 at 19:46
  • What are the values of `TABLE` and `$user`. What do you get if you `echo()` the query. – Spudley Jun 02 '13 at 19:47
  • @pilsetnieks i'm seeing everybody stressing this when were they deprecated? – pinkpanther Jun 02 '13 at 19:47
  • What does `mysql_error()` tell you? Also, the `mysql_*` functions are deprecated; you should use [MySQLi](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/book.pdo.php). – FThompson Jun 02 '13 at 19:48
  • @pinkpanther - Formal deprecation is coming in PHP 5.5 (currently in beta; due out immently). Prior to that the PHP devs operated a "soft deprecation" for them; they put warnings up on the manual pages not to use them some time ago, but didn't make them actually throw warnings before now due to the numbers of people still using them. Now that the message is getting through, they are going ahead with the formal depreaction. See also http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Spudley Jun 02 '13 at 19:53
  • do you have error reporting enabled for PHP? – ply Jun 02 '13 at 19:54
  • 2
    You must not `or die(...)` from a `mysql_fetch_*()` call. If _no rows_ are returned from the query, your fetch call will return `FALSE` and your error will trigger. That is _not_ an error state, however. It's just no rows from the query. (but this isn't your problem here, since you are not seeing the `fetch array` message) – Michael Berkowski Jun 02 '13 at 19:57
  • A blank screen means a PHP fatal error, either a syntax error or fatal runtime error. Turn on error reporting - `error_reporting(E_ALL); ini_set('display_errors', 1);` _always_ in development. – Michael Berkowski Jun 02 '13 at 19:58
  • how is defined TABLE ? – echo_Me Jun 02 '13 at 20:50

3 Answers3

0

better do this, then you know what the error is:

$data = mysql_fetch_array($table) or die(mysql_error());
doniyor
  • 36,596
  • 57
  • 175
  • 260
  • Actually, better use `PDO` instead of `mysqli_*` and `mysql_*`. `mysql_*` is deprecated already. – tftd Jun 02 '13 at 20:16
0

try this

$table = mysql_query("SELECT * FROM '" . TABLE . "' WHERE username='$user'") or die(mysql_error());
echo_Me
  • 37,078
  • 5
  • 58
  • 78
0

Assuming constant TABLE is set and variable $user is a valid string, and you get no errors, the mos likely explanation is that the row is not there in the table.