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:
- Code: Select all
<?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'] ) {
$result = mysql_query('SELECT * FROM chatitems WHERE user = '.
mysql_real_escape_string( $_REQUEST['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
}
mysql_free_result($result);
?>
</chat>
Thanks,
Sam


