hi, the user is supposed to enter their favorite actor, and the database gets updated, and the vote added. then it is supposed to display the top 10 actors the users voted for, but i get an error. here is there error.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/oddnerdrum.info/TOPTEN/actors/actors.php on line 42
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/oddnerdrum.info/TOPTEN/actors/actors.php on line 67
here is the code to the page, any help GREATLY appreciated. thank you. derek
Code:
<?php
// connect to database include file
//include("connect2.php");
include("connect2.php");
$checkIp = FALSE; // Set to tru to enable ip checking
ini_set('display_errors', 1);
error_reporting(E_ALL);
// escape username and password for use in SQL//person said on board "looks fine" like this
//to prevent sql injections
function post($fieldname = '') {
$data = '';
if($fieldname!='' AND isset($_POST[$fieldname])) $data = $_POST[$fieldname];
return $data;
}
if($_POST) {
$actor = post('actor');
$actor = strip_tags(mysql_real_escape_string($actor));
}
if(isset($_POST['Submit']) AND isset($_POST['vote']))
{
$Check = mysql_query("SELECT * FROM actor_voters WHERE IP='".$_SERVER['REMOTE_ADDR']."'");
$num = mysql_num_rows($Check);
if(!$checkIp) $num = 0;
if($num < 1) // counts if the ip is less than 1, if it is more than 1 it means that someone already voted.
{
echo (" You have voted for a ".$actor. " <br /><br />");
$check1 = mysql_query("SELECT vote FROM actors WHERE `actor`='{$actor}' ");
if(mysql_num_rows($check1)>0)
{
$row = mysql_fetch_array($check1);
$vote = $row['vote'] + 1;
mysql_query("UPDATE actors SET vote='$vote' WHERE `actors`='{$actor}' ");
}
else
{
$sql = "INSERT INTO actors (`actor`) VALUES('{$actor}' ,'1')";
mysql_query($sql);
}
if($checkIp) mysql_query("INSERT INTO actor_voters (ip) VALUES('{$_SERVER['REMOTE_ADDR']}')");
}
else
{
echo "sorry, you can just vote once.";
}
}
if($_POST) {
$query="SELECT * FROM actors ORDER BY vote DESC LIMIT 10";
$result=mysql_query($query);
if(mysql_num_rows($result) > 0)
{
echo "Top ten actors :<br />";
echo '<table border="1">
<tr>
<td>Actor</td>
<td>Vote</td>
</tr>
';
while($row = mysql_fetch_array($result))
{
echo '<tr>
<td>'.$row['actor'].' </td>
</tr>
';
}
echo '</table>';
}
else
{
echo "No actors in the database";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>cars </title>
</head>
<body>
</p>
<div align="center">welcome to <strong>vote for your favorite actor</strong> </div>
<p>Please enter your vote your favorite actor.<span class="style4"></span><br />
</p>
<form id="form1" name="form1" method="post" action="">
<table border="0">
<tr>
<td>Actor</td>
<td>
<input name="make" type="text" id="actor" /></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit" value="Submit" />
<input type="hidden" name="vote" value="TRUE" /> </td>
</tr>
</table>
</form>
<form id="form2" name="form2" method="post" action="">
<table width="666" border="1">
<tr>
<td width="42"> </td>
<td width="608"><div align="center">VIEW THE UPDATED TOP TEN ACTORS</div></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
|