cs1h Posted April 14, 2008 Share Posted April 14, 2008 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 https://forums.phpfreaks.com/topic/101026-call-to-a-member-function-on-a-non-object-help/ Share on other sites More sharing options...
trq Posted April 14, 2008 Share Posted April 14, 2008 $sql is a string, not an object. You likely need to call $db query as you do further down, however, I don't see where you define $db either. Link to comment https://forums.phpfreaks.com/topic/101026-call-to-a-member-function-on-a-non-object-help/#findComment-516642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.