Jump to content

'Call to a member function on a non-object' help


cs1h

Recommended Posts

Hi, I am trying to get a star rating script working but I get the following error.

 

Fatal error: Call to a member function on a non-object in D:\Inetpub\vhosts\asfdhjfk.com\httpdocs\tester\rate.php on line 11

 

the code is,

 

<?php
include("DB.php");

mysql_connect($server, $db_user, $db_pass) 
or die ("Could not connect to mysql because ".mysql_error()); 

$id = $_GET['id'];
$title = '';

$sql = "SELECT name FROM movies WHERE movie_id=$id";
while( $sql->fetchInto( $row ) ) { $title = $row[0]; }
?>
<html>
<head>
<title><?php echo($title); ?></title>
<script src="prototype.js"></script>
<script>
function rate( value ) {
new Ajax.Updater( 'rating', 'ratemovie.php?id=<?php echo($id)?>&v='+value );
}
</script>
</head>
<body>
<h1><?php echo($title); ?></h1>

<div id="rating">
<img src="star_off.gif" onClick="rate(1)"></img>
<img src="star_off.gif" onClick="rate(2)"></img>
<img src="star_off.gif" onClick="rate(3)"></img>
<img src="star_off.gif" onClick="rate(4)"></img>
<img src="star_off.gif" onClick="rate(5)"></img>
<br/><br/>
<?php
$res2 = $db->query(
'SELECT count( rating ), sum(rating ) FROM ratings WHERE movie_id=?',
$id
);
while( $res2->fetchInto( $row ) )
{
?>
Votes: <?php echo($row[0]); ?><br/>
Average Rating: <?php echo($row[1]/$row[0]); ?>
<?php
}
?>
</div>

</body>
</html>

 

I don't know what to do about it. Can anyone help?

 

Thanks,

 

Colin

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.