|
Hi, I'm having some problems with accessing the results from a MySQL database. This script is the edit page of a news script. If gets the existing news from the database and puts it into a form. However whenever I add the line:
$row = mysql_fetch_row($result)
I get the following error message.
Parse error: parse error, unexpected T_VARIABLE in /home/sites/site69/web/church/editnews.php on line 53
I'm quite new to PHP and just can't figure this one out. The code I'm using is shown below. I have blanked the MySQL username and password fields so they aren't the problem. I hope you can help.
<?
// Define database connection details
$dbHost = "localhost";
$dbUser = "*****";
$dbPass = "*****";
$dbName = "news";
$table = "news";
// Attempt to connect the the MySQL server
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
// If the connection was unsuccessful
if (!$link)
{ // Report error and exit
echo "<P>Couldn't connect to server</P>";
exit;
}
// Attempt to select database. If unsuccessful....
if (!@mysql_select_db($dbName))
{ // Report error and exit
echo "<P>Could not select $dbName database</P>";
exit;
}
// Build query to fetch news item from database
$query = "SELECT * FROM news WHERE newsID=$newsID";
// Execute query
$result = @mysql_query($query);
// If query was okay AND we have returned a result
if ($result && @mysql_num_rows($result) > 0)
{ // Start building the HTML form
$row = mysql_fetch_row($result)
$newsText = "";
$newsText .= "<FORM METHOD='POST' ACTION='addnews.php'>";
// Add a hidden field to hold the newsID
$newsText .= "<INPUT TYPE='HIDDEN' NAME='newsID' VALUE=" . $row['newsID'] . ">";
// Add username and password fields
$newsText .= "<BR>Username:";
$newsText .= "<BR><INPUT TYPE='TEXT' NAME='username'>";
$newsText .= "<BR>Password:";
$newsText .= "<BR><INPUT TYPE='PASSWORD' NAME='password'>";
// Retrieve the title from the database
$newsText .= "<BR>Title:";
$newsText .= "<BR><INPUT TYPE='TEXT' NAME='title' VALUE=" . stripslashes($row['title']) . ">";
// Retrieve the author from the database
$newsText .= "<BR>Author:";
$newsText .= "<BR><INPUT TYPE='TEXT' NAME='author' VALUE=" . $row['author'] . ">";
// Retrieve the body from the database
$newsText .= "<BR>Body:";
$newsText .= "<BR><TEXTAREA NAME='body' ROWS='5'>";
$newsText .= stripslashes($row['body']);
$newsText .= "</TEXTAREA>";
// Add submit button
$newsText .= "<BR><BR><INPUT TYPE='SUBMIT' VALUE='Submit'></FORM>";
// Output the form
echo "$newsText";
}
else
{ // If no news items were found
echo "<P>That news item does not appear to be in the database</P>";
}
// Close link to MYSQL server
mysql_close($link);
?>
|