ProcalX Posted April 20, 2011 Share Posted April 20, 2011 Morning all, I'm trying to query a user table and am receiving errors. In the mysql statement I am trying to SELECT all data from the table that matches the username of the person logged in. The error I am receiving is this: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\123\myaccount.php The database query is written correctly, if I am logged in as the user Admin then I recieve this message as well: Unknown column 'Admin' in 'where clause' from the or die(mysql_error());. In the database the username is: admin but I can login using Admin, is this an issue of upper and lowercase? The PHP code is below: <?php require_once('connect.php'); $query = mysql_query("SELECT * FROM user WHERE username = $_SESSION[gatekeeper]"); while ($row = mysql_fetch_array($query) or die(mysql_error())); { echo"<div class='BlockContent'>"; echo" <table id='UserList'>"; echo" <tr>"; echo" <th>My Account</th>"; echo" </tr>"; echo" <tr>"; echo" <td id='left'>"; echo" </td>"; echo" </tr>"; echo" </table>"; echo"</div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/234231-query-failing-on-upperlowercase/ Share on other sites More sharing options...
Nodral Posted April 20, 2011 Share Posted April 20, 2011 Hi Try moving the variable out of the brackets and concatenating it. I have the same issue sometimes and find that when usingf a variable from an array it crashes. <?php require_once('connect.php'); $query = mysql_query("SELECT * FROM user WHERE username = " . $_SESSION[gatekeeper]); Stu Link to comment https://forums.phpfreaks.com/topic/234231-query-failing-on-upperlowercase/#findComment-1203894 Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 You must wrap your $_SESSION['gatekeeper'] in single quotes as it is a string. Also, you'r or die statement should be against the mysql_query() NOT the mysql_fetch_array(). in addition it is better practice to assign the query text to a variable before running the mysql_query() against it. here: $sql = "SELECT * FROM user WHERE username = '$_SESSION[gatekeeper]'"; $query = mysql_query($sql) or die ('ERROR :<br>'.mysql_error().'<br><br>When Running<br><br>'.$sql); while ($row = mysql_fetch_array($query){ ... Also, try to avoid using SELECT * Link to comment https://forums.phpfreaks.com/topic/234231-query-failing-on-upperlowercase/#findComment-1203897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.