Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
need help with this voting script please
Old 01-29-2010, 10:27 AM need help with this voting script please
Webmaster Talker

Posts: 611
Trades: 0
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'].'&nbsp;</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>&nbsp;</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">&nbsp;</td>
      <td width="608"><div align="center">VIEW THE UPDATED TOP TEN ACTORS</div></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" id="submit" value="submit" /></td>
    </tr>
  </table>
</form>

</body>
</html>
silverglade is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-29-2010, 11:25 AM Re: need help with this voting script please
Extreme Talker

Posts: 177
Trades: 0
After each msyql_query you should add or die($query . $error) to get a better idea of whats going on. There are probably some values being used in teh query that are null.

As follows:

PHP Code:
$selectStatement "...";
$query mysql_query($selectStatement) or die($selectStatement mysql_error()); 
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 01-29-2010, 01:17 PM Re: need help with this voting script please
Webmaster Talker

Posts: 611
Trades: 0
great thank you. do you see any errors in the code in a quick glance? thanks very much. derek
silverglade is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to need help with this voting script please
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11210 seconds with 12 queries