Jump to content

please, need help coding this voting for your favorite car polling system.


silverglade

Recommended Posts

hi, my code needs a lot of work, but i want to be able to let users vote on their favorite car, update the database, and display the new updated data for the top ten cars listed. i want to prevent multiple votes by ip but i dont know how, but any help with the voting part of the code GREATLY appreciated, as my google tutorials seem to only show premade code.

 

here is the page so far.

 

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


ini_set('display_errors', 1);
  error_reporting(E_ALL);   // GREAT SNIPPET FOR DEBUGGING OUTPUTS ERRORS TO SCREEN */

////////////////////////////////////////
////////////////////////////////////////


// escape username and password for use in SQL//person said on board "looks fine" like this
//to prevent sql injections
  
$make= $_POST['make'];
$model  = $_POST['model'];
$year  = $_POST['year'];
$color   = $_POST['color'];


$make = mysql_real_escape_string($make);
$model = mysql_real_escape_string($model);
$year = mysql_real_escape_string($year);
$color = mysql_real_escape_string($color);

$find = $_POST['find'];


    


if(isset($_POST['Submit'])){

  $vote=0;
$vote++;

  echo (" You have voted for a ".$color. " ".$make." ".$model. " ...year: ".$year.".");

mysql_query("INSERT INTO cars (make, model, year ,color , vote ) VALUES('$make','$model', '$year' , '$color',' $vote'"); //ON DUPLICATE KEY UPDATE courtesy = courtesy + $courtesy,  stability = stability + $stability, loyalty = loyalty + $loyalty, attitude = attitude + $attitude, votes = votes + $votes");


}//end isset

  
  
  
  //output the cars row into an array and the list the top ten
if(isset($_POST['submit'])){
  $query="SELECT make, model, year, color, vote 
FROM cars
WHERE votes (is the most number of votes) ;
$result=mysql_query($query); 

if(mysql_num_rows($result) > 0)
{
$topcars = mysql_fetch_array($result); //put cars row into an array $topcars

}

echo( "Top ten cars ". $carone."<br>".$cartwo."<br>". $carthree. "<br>".$carfour."<br>".
$carfive."<br>".$carsix. "<br>". $carseven. "<br>".$careight."<br>".$carnine."<br>".$carten .<br>");

}//end isset
    
?>
<!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>Top ten .com </title>
</head>

<body>
</p>
<div align="center">welcome to <strong>vote your cars</strong>  </div>
<p>Please enter your vote your favorite car.<span class="style4"></span><br />
</p>
<form id="form1" name="form1" method="post" action="cars.php">

  <table border="0">
   
    <tr>
      <td>Make</td>
      <td>
        <input name="make" type="text" id="make" /></td>
    </tr>
    <tr>
      <td>Model</td>
      <td>
       <input name="model" type="text" id="model" />      </td>
    </tr>
    <tr>
      <td>Year</td>
      <td><input name="year" type="text" id="year" /></td>
    </tr>
    <tr>
      <td>Color</td>
      <td><input type="color" name="textfield" id="color" /></td>
    </tr>
   
    <tr>
      <td> </td>
      <td><input type="submit" name="Submit" value="Submit" /></td>
    </tr>
  </table>
   
  
</form>
<form id="form2" name="form2" method="post" action="cars.php">
<table width="666" border="1">
    <tr>
      <td width="42"> </td>
      <td width="608"><div align="center">VIEW THE UPDATED TOP TEN CARS</div></td>
    </tr>
    
    <tr>
      <td> </td>
      <td><input type="submit" name="submit" id="submit" value="submit" /></td>
    </tr>
  </table>
</form>

</body>
</html>

Link to comment
Share on other sites

simple how to prevent dubbel ip votes :

 

make new table called IP.

than change this line to:

 

mysql_query("INSERT INTO cars (make, model, year ,color , vote, IP ) VALUES('$make','$model', '$year' , '$color',' $vote','$_SERVER['REMOTE_ADDR']'");

 

that way you will put the users IP in the database, and just make a check.

like this one

 

$Check = mysql_query("SELECT * FROM basket WHERE  IP='".$_SERVER['REMOTE_ADDR']."'");

$num = mysql_num_rows($Check);

if($num < 1) // counts if the ip is less than 1, if it is more than 1 it means that someone already voted.

{

mysql_query("INSERT INTO cars (make, model, year ,color , vote, IP ) VALUES('$make','$model', '$year' , '$color',' $vote','$_SERVER['REMOTE_ADDR']'");

}

else

{

echo "sorry, you can just vote once."

}

 

i use this script for my webshop www.lovelyfamous.com

hope it works for you

 

 

Link to comment
Share on other sites

im getting a blank screen with the following code, please, any help greatly apreciated. thanks. derek

 

<?php
// connect to database include file

include("connect1.php");




ini_set('display_errors', 1);
  error_reporting(E_ALL);   // GREAT SNIPPET FOR DEBUGGING OUTPUTS ERRORS TO SCREEN */

////////////////////////////////////////
////////////////////////////////////////


// escape username and password for use in SQL//person said on board "looks fine" like this
//to prevent sql injections
  
$make= $_POST['make'];
$model  = $_POST['model'];
$year  = $_POST['year'];
$color   = $_POST['color'];


$make = mysql_real_escape_string($make);
$model = mysql_real_escape_string($model);
$year = mysql_real_escape_string($year);
$color = mysql_real_escape_string($color);



    


if(isset($_POST['Submit'])){

  $vote=0;
$vote++;

  echo (" You have voted for a ".$color. " ".$make." ".$model. " ...year: ".$year.".");



/* ONLY VOTING ONCE BASED ON IP CODE <br />
that way you will put the users IP in the database, and just make a check.
like this one*/

$Check = mysql_query("SELECT * FROM cars WHERE  IP='".$_SERVER['REMOTE_ADDR']."'");
      $num = mysql_num_rows($Check);
      if($num < 1) // counts if the ip is less than 1, if it is more than 1 it means that someone already voted.
      {
mysql_query("INSERT INTO cars (make, model, year ,color , vote, IP ) VALUES('$make','$model', '$year' , '$color',' $vote','$_SERVER['REMOTE_ADDR']'");
}
else
{
echo "sorry, you can just vote once."
}


}//end isset

  
/* 
  
  //output the cars row into an array and the list the top ten
if(isset($_POST['submit'])){
  $query="SELECT make, model, year, color, vote 
FROM cars
WHERE votes (is the most number of votes) ;
$result=mysql_query($query); 

if(mysql_num_rows($result) > 0)
{
$topcars = mysql_fetch_array($result); //put cars row into an array $topcars

}

echo( "Top ten cars ". $carone."<br>".$cartwo."<br>". $carthree. "<br>".$carfour."<br>".
$carfive."<br>".$carsix. "<br>". $carseven. "<br>".$careight."<br>".$carnine."<br>".$carten .<br>");

}//end isset
   */ 
?>
<!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>Top ten .com </title>
</head>

<body>
</p>
<div align="center">welcome to <strong>vote your cars</strong>  </div>
<p>Please enter your vote your favorite car.<span class="style4"></span><br />
</p>
<form id="form1" name="form1" method="post" action="cars.php">

  <table border="0">
   
    <tr>
      <td>Make</td>
      <td>
        <input name="make" type="text" id="make" /></td>
    </tr>
    <tr>
      <td>Model</td>
      <td>
       <input name="model" type="text" id="model" />      </td>
    </tr>
    <tr>
      <td>Year</td>
      <td><input name="year" type="text" id="year" /></td>
    </tr>
    <tr>
      <td>Color</td>
      <td><input type="color" name="textfield" id="color" /></td>
    </tr>
   
    <tr>
      <td> </td>
      <td><input type="submit" name="Submit" value="Submit" /></td>
    </tr>
  </table>
   
  
</form>
<form id="form2" name="form2" method="post" action="cars.php">
<table width="666" border="1">
    <tr>
      <td width="42"> </td>
      <td width="608"><div align="center">VIEW THE UPDATED TOP TEN CARS</div></td>
    </tr>
    
    <tr>
      <td> </td>
      <td><input type="submit" name="submit" id="submit" value="submit" /></td>
    </tr>
  </table>
</form>

</body>
</html>

Link to comment
Share on other sites

IP-based voting is far from efficient as users (like me) can (with a press on the button) change their IP-address thus allowing me to vote as many times as my ISP would possibly allow me to (somewhere near 50-60% of the IP-range provided to my ISP as every ISP has more IP-addresses available then it has possible customers). So basically I can vote for every IP for which my ISP has no customer and that is presumably more then the average number of visits a very popular website has :D

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.