Jump to content

Vote once with ON / OFF feature

- - - - -

  • Please log in to reply
3 replies to this topic

#1
v3inte

v3inte

    Newbie

  • Members
  • Pip
  • 4 posts
Good day,
im using this code posted somewhere on this section,.

<?php 

mysql_connect("localhost", "root", "password"); 

mysql_select_db("webcodez"); 

?> 

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">  

<input type="submit" name="submit" value="dai to4ka" class="bt_register" />  

</form>  

<?php  

$id = (int)$_GET['id'];  

if($_POST['submit']=='dai to4ka')  

{  

$timeout=10; //60*60*24 seconds = 1 day  

$time=time();  

$out=$time-$timeout;  

$ip=$_SERVER['REMOTE_ADDR'];  

$check_double=mysql_query("SELECT * FROM ips WHERE ip='$ip' AND time>$out")or die(mysql_error());  


if(mysql_num_rows($check_double)>0){  

echo "one time pls ";  

}  

else{  

echo "success"; 

$vote=mysql_query("INSERT INTO ips(ip,time) VALUES('$ip','$time')");  

//$query = mysql_query(" UPDATE `tz_members` SET point = point + 1 WHERE id = $id;") or die(mysql_error());  

}  


} 

It works fine, but i want to add a STATUS: ON / OFF

if the status is ON then the user can vote..
otherwise, if status is OFF, the user can't vote at all + error message saying "Voting is off, you can't vote at this moment"

btw, changing of status can only be access by the admin side..
Thank you so much..

#2
v3inte

v3inte

    Newbie

  • Members
  • Pip
  • 4 posts
any help will be much appreciated.
thank you :)

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You really haven't given us much to work with. How are you going to track that the status is on/off? If the status is off, why would you display the form to a user in the first place?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
v3inte

v3inte

    Newbie

  • Members
  • Pip
  • 4 posts
i have this code, it actually check in the table "songreqstat" if the status is Yes / no
dont get bothered by the table name and other names there, because i revised it to suit my needs..
the other element still the same, i just want to test it..


<?php

 // check the value from the voting status table

 $qry = "SELECT status FROM songreqstat";

 $sql = mysql_query($qry);

 $ary = mysql_fetch_array($sql);

 $value = $ary['status'];

if (strtolower($value) == 'yes') {


echo "<form action='<?=$_SERVER['PHP_SELF'];?>' method='post'>";

echo "<input type='submit' name='submit' 


value='Submit'></form>";


$id = (int)$_GET['id'];  

if($_POST['submit']=='Submit')  

{  

$timeout=10; //60*60*24 seconds = 1 day  

$time=time();  

$out=$time-$timeout;  

$ip=$_SERVER['REMOTE_ADDR'];  

$check_double=mysql_query("SELECT * FROM ips WHERE ip='$ip' AND 


time>$out")or die(mysql_error());  


if(mysql_num_rows($check_double)>0){  

echo "Sorry, But you've already made a request earlier. Try 


again after 30 minutes. Thank you!";  

}  

else{  

echo "Thank you for requesting a song. <br> Please wait the DJ 


to approve/decline your request. <br> Thank 


you!"; 

$reqonce=mysql_query("INSERT INTO ips(ip,time) 


VALUES('$ip','$time')");  

//$query = mysql_query(" UPDATE `tz_members` SET point = point + 


1 WHERE id = $id;") or die(mysql_error());  

}  


}

}

else {

echo "Sorry, Song Request will not be entertained at this 


moment.<br>a Current DJ is playing/finishing all 


remaining song request(s).<br>or DJ is not accepting song 


request anymore.";

}

?>

when i run the code, i get this error..

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/***private***/public_html/test.php on line 13

line 13 state:
echo "<form action='<?=$_SERVER['PHP_SELF'];?>' method='post'>";





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users