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 http://freedom-apps.co.uk/chat/messages.php. 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: http://freedom-apps.co.uk/chat/messages.php?user=u which returns an error. Any ideas? My code is:
<?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');
}
?>
<chat>
<?php
while ($row = mysql_fetch_assoc($result)) {
?>
<message added="<?php echo( $row['added'] ) ?>"
id="<?php echo( $row['id'] ) ?>">
<user><?php echo( htmlentities( $row['user'] ) ) ?></user>
<text><?php echo( htmlentities( $row['message'] ) ) ?></text>
</message>
<?php
}
var_dump($result);
mysql_free_result($result);
?>
</chat>
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).
Thanks, Sam