Jump to content

Recommended Posts

I'am doing this tutorial from one of my books and I have copied it all word for word but when it comes to testing I'am gettin alot of errors, I don't know if it's old code syntax or what but I need help.

 

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

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

}

    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.iA" , 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 != ) {
		$range = ($a / 10) - 0.5;
	}
	else {
		$range = $a / 10;
	}

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

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

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

	for($range=1;$range<=$remain;$range++) {
		echo "<img src='" . $config_basedir . "news/off.gif'>";
	}
}
       echo "<br />";
       
       echo "<strong>Rate this story</strong>: ";
       
       if($_SESSION['SESS_USERNAME']) {
	for($i=1;$i<=10;$i++) {
		echo "<a href='ratestory.php?id=" . $validid . "&rating=" . $i . "'>" . $i . "</a> ";
	}
}
else {
	echo "To vote, please <a href='userlogin.php'>login</a>.";
}

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



?>

Parse error: parse error, unexpected ')' in C:\file\file\file\viewstory.php on line 38.

 

The book is called practical php and mysql 'building eight dynamic web applications'.

this code is for a news website and this code is viewstory.php

It never siezes to amaze me how books do not teach proper coding strategies.

 

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

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

}

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.iA" , 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) != ) { // Does not equal WHAT?????
	$range = ($a / 10) - 0.5;
}
else {
	$range = $a / 10;
}

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

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

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

for($range=0;$range<$remain;$range++) {
	echo "<img src='" . $config_basedir . "news/off.gif'>";
}
}
      echo "<br />";
      
      echo "<strong>Rate this story</strong>: ";
      
      if($_SESSION['SESS_USERNAME']) { 
	for($i=1;$i<=10;$i++) {
		echo "<a href='ratestory.php?id=" . $validid . "&rating=" . $i . "'>" . $i . "</a> ";
	}
}
else {
	echo "To vote, please <a href='userlogin.php'>login</a>.";
}

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

?>

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.