Jump to content

[SOLVED] Unexpected ')' help


GreenUser

Recommended Posts

Hi all!

 

I am a little lost why I receive these error's, am working from a book.  Of course, the page doesn't display. 

 

PHP Parse error:  syntax error, unexpected ')' in C:\\Program Files\\Apache\\htdocs\\news\\viewstory.php on line 38

 

When I comment out that line, line 49 has an unexpected ')' as well. 

 

<?php

require("config.php");
require("functions.php");

if(pf_check_number($_GET['id']) == TRUE) {
$validid = $_GET['id'];
}
else {
header("Location: " . config_basedir . "/index.php");
}

require("header.php");

$sql = "SELECT * FROM stories WHERE id = " . $validid . ";";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

echo "<h1>" . $row['subject'] . "</h1>";
echo date("D jS F Y g:i A", strtotime($row['dateposted'])) . "<br />";
echo nl2br($row['body']);

$avgsql = "SELECT COUNT(id) AS number, AVG(rating) AS avg FROM ratings WHERE story_id = " . $validid . ";";
$avgresult = mysql_query($avgsql);
$avgrow = mysql_fetch_assoc($avgresult);

echo "<p>";
echo "<strong>Rating</strong> ";

if($avgrow['number'] == 0) {
echo "No Ratings!";
}

else {
$a = (round($avgrow['avg'] * 2) / 2) . "<br>";
$a *= 10;
}
if($a%5 == 0 && $a%10 != ) {                   /// line 38
	$range = ($a / 10) - 0.5;
}
else {
	$range = $a / 10;
}

for($i=1;$i<=$range;$i++) {
echo "<img src='" . $config_basedir . "img/full.gif'>";
}

if($a%5 == 0 && $a%10 != ) {
echo "<img src='" . $config_basedir . "img/half.gif'>";
}

$a = $a / 10;
$remain = 10 - $a;

for($r=1;$r<=$remain;$r++) {
	echo "<img src='" . $config_basedir . "img/none.gif'>";
	}

	{
	echo "<br />";

	echo "<strong>Rate this story</strong>: ";

	if($_SESSION['SESS_USERNAME']) {
		for($i=1;$i<=10;$i++) {
			echo "<a href='ratestroy.php?id=" . $validid . "&rating=" . $i . "'>" . $i . "</a> ";
		}
	}
	else {
		echo "To vote, please <a href='userlogin.php'>log in</a>.";
	}

echo "</p>";
require("footer.php");

?>

 

Thank you

Link to comment
Share on other sites

<?php

require("config.php");
require("functions.php");

if(pf_check_number($_GET['id']) == TRUE) {
$validid = $_GET['id'];
}
else {
header("Location: " . config_basedir . "/index.php");
}

require("header.php");

$sql = "SELECT * FROM stories WHERE id = " . $validid . ";";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

echo "<h1>" . $row['subject'] . "</h1>";
echo date("D jS F Y g:i A", strtotime($row['dateposted'])) . "<br />";
echo nl2br($row['body']);

$avgsql = "SELECT COUNT(id) AS number, AVG(rating) AS avg FROM ratings WHERE story_id = " . $validid . ";";
$avgresult = mysql_query($avgsql);
$avgrow = mysql_fetch_assoc($avgresult);

echo "<p>";
echo "<strong>Rating</strong> ";

if($avgrow['number'] == 0) {
echo "No Ratings!";
}

else {
$a = (round($avgrow['avg'] * 2) / 2) . "<br>";
$a *= 10;
}
if($a%5 == 0 && $a%10 != null) {                   /// line 38
	$range = ($a / 10) - 0.5;
}
else {
	$range = $a / 10;
}

for($i=1;$i<=$range;$i++) {
echo "<img src='" . $config_basedir . "img/full.gif'>";
}

if($a%5 == 0 && $a%10 != null ) {
echo "<img src='" . $config_basedir . "img/half.gif'>";
}

$a = $a / 10;
$remain = 10 - $a;

for($r=1;$r<=$remain;$r++) {
	echo "<img src='" . $config_basedir . "img/none.gif'>";
	}

	{
	echo "<br />";

	echo "<strong>Rate this story</strong>: ";

	if($_SESSION['SESS_USERNAME']) {
		for($i=1;$i<=10;$i++) {
			echo "<a href='ratestroy.php?id=" . $validid . "&rating=" . $i . "'>" . $i . "</a> ";
		}
	}
	else {
		echo "To vote, please <a href='userlogin.php'>log in</a>.";
	}

echo "</p>";
require("footer.php");

?>

 

Try that now. I added null to the last bit.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.