mage1 Posted October 5, 2008 Share Posted October 5, 2008 how can i block the username of the person who already voted? heres my code <?php include("mysql.php"); $username=$_SESSION["username"]; mysql_query("select * from regusers where username='$username'"); echo "<strong>You already voted!<br /></strong>"; //connect to MySQL $db=new mysqli('localhost','root',''); if(!$db->select_db('poll1')) //create the database $db->query('create database poll1'); //select the database $db->select_db('poll1'); //create table if(!$db->query('select * from polldb')) { $db->query('create table polldb (id int auto_increment primary key, option1 int, option2 int, option3 int)'); $db->query("insert into polldb (option1, option2, option3) values (0,0,0)"); } //someone will vote if($_GET['action']=='Vote') { $option1=$_GET['option1']; $option2=$_GET['option2']; $option3=$_GET['option3']; if($option1!='' || $option2!='' || $option3!='') { //fetch initial values of polls in DB $result=$db->query("select * from polldb"); $result=$result->fetch_row(); $op1=$result[1]; $op2=$result[2]; $op3=$result[3]; //increment the voted option if($option1=='voted') $op1++; elseif($option2=='voted') $op2++; elseif($option3=='voted') $op3++; //save the updated values $db->query("update polldb set option1='$op1', option2='$op2', option3='$op3'"); //redirect to results page //by setting the $_GET var $_GET['action']='Results'; } } if($_GET['action']=='Results') { //fetch initial values of polls in DB $result=$db->query("select * from polldb"); $result=$result->fetch_row(); $op1=$result[1]; $op2=$result[2]; $op3=$result[3]; //close DB $db->close(); ?> Link to comment https://forums.phpfreaks.com/topic/127081-php-polling-blocking-username-instead-of-ip/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.