Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't this PHP mysql_query getting the correct info from my database?
    primarykey
    data
    text
    <p>I'm relatively new to this, so sorry if I'm posting in the wrong place. I've got a table in my database which holds 4 things - id, time put in and user and message (for a basic chat-room style thing). I'm trying to call these using a PHP page. But my page just gets returned blank when I put an argument in the address bar. I'm trying to call it so that only lines with a certain user in the user column get shown. My code is below - can anybody see what I am doing wrong? The URL of the file is <a href="http://freedom-apps.co.uk/chat/messages.php" rel="nofollow">http://freedom-apps.co.uk/chat/messages.php</a>. You see a load of entries - at the start, there is u m u m u m. U represents the user entered, m is the message. So I tried: <a href="http://freedom-apps.co.uk/chat/messages.php?user=u" rel="nofollow">http://freedom-apps.co.uk/chat/messages.php?user=u</a> which returns an error. Any ideas? My code is:</p> <pre><code>&lt;?php header( 'Content-type: text/xml' ); mysql_connect('localhost:/var/lib/mysql/mysql.sock', 'freedom_ASAPPS', '********'); mysql_select_db( 'freedom_chat_alpha' ); if ( $_REQUEST['user'] ) { $user = mysql_escape_string($_REQUEST['user']); $result = mysql_query('SELECT * FROM chatitems WHERE user = '$user' ORDER BY added LIMIT 50'); } else { $result = mysql_query('SELECT * FROM chatitems ORDER BY added LIMIT 50'); } ?&gt; &lt;chat&gt; &lt;?php while ($row = mysql_fetch_assoc($result)) { ?&gt; &lt;message added="&lt;?php echo( $row['added'] ) ?&gt;" id="&lt;?php echo( $row['id'] ) ?&gt;"&gt; &lt;user&gt;&lt;?php echo( htmlentities( $row['user'] ) ) ?&gt;&lt;/user&gt; &lt;text&gt;&lt;?php echo( htmlentities( $row['message'] ) ) ?&gt;&lt;/text&gt; &lt;/message&gt; &lt;?php } var_dump($result); mysql_free_result($result); ?&gt; &lt;/chat&gt; </code></pre> <p>I believe it is something wrong with line 6 and 7, or in the way I call the php page with the argument (see above). I've being referring to the book I have used to learn this stuff, and still can't figure it out (Learning PHP, MySQL, and JavaScript: A Step-by-Step Guide to Creating Dynamic Websites).</p> <p>Thanks, Sam</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload