Query Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Query Help

Post by Smackie »

hey i am trying to query one of my databases and i keep getting an error

here is the code..

Code: Select all

<?php

if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
   echo 'Could not connect to mysql';
   exit;
}

if (!mysql_select_db('mysql_dbname', $link)) {
   echo 'Could not select database';
   exit;
}

$sql    = 'SELECT * FROM chat WHERE id = 0';
$result = mysql_query($sql, $link);

if (!$result) {
   echo "DB Error, could not query the database\n";
   echo 'MySQL Error: ' . mysql_error();
   exit;
}

while ($row = mysql_fetch_assoc($result)) {
   echo $row['chat'];
}

mysql_free_result($result);

?>
here is the error im getting
Parse error: parse error, unexpected T_STRING in chat.php on line 6
can someone see whats wrong because i cant see anything wrong
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

change

Code: Select all

if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password'))
to

Code: Select all

$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password');
if (!$link) {
Post Reply