Well as i'm trying to create a PHP Voting Poll Script, some errors occurred... I was able to rectify some... but one is really killing me:S:S i created a while($fetch= mysql_fetch_array($query)){...}... but the problem is that the things written in the {...} area couldnt be seen:S here's the code... <?include('connect.php')?> <?php $submit= $_POST['submit']; $id = $_POST['id']; include('admin/config.php'); $choice = $_POST['choice']; $ip = $_SERVER['REMOTE_ADDR']; "<form method='post' action=".$_SERVER['PHP_SELF']." > <input type='hidden' value=" .$ip."></form>"; ?> <? if(isset($submit)){ $sql = 'INSERT INTO `warzone`.`recog` (`id`, `ip`, `pollid`) VALUES (NULL, \'' .$ip. '\', \'' .$id. '\');'; $query = mysql_query($sql); if(!$_POST['choice']){echo "<font color='red'> Please Select an Option </font>";} if($ip == $fetch['ip']){ echo "You already submitted your vote!";} else{$sql ='SELECT * FROM `poll` SELECT * FROM `recog ;'; $query = mysql_query($sql);} while($fetch = mysql_fetch_array($query)){ echo $fetch['question']?> [HTML]<form method='post' action=<? $_SERVER['PHP_SELF'] ?>" > <input type='hidden' name='id' value="<? echo $fetch['id'] ?>"> <input type='radio' name='choice' value='1'><? echo $fetch['one'] ?><br/> <input type='radio' name='choice' value='2'> <? echo $fetch['two']?><br/> <input type='radio' name='choice' value='3'> <? echo $fetch['three']?><br/> <input type='radio' name='choice' value='4'><? echo $fetch['four'] ?><br/> <input type='submit' name='submit' value='Vote!'></form> <? } if($choice == 1) $str= "one"; elseif($choice == 2) $str= "two"; elseif($choice == 3) $str= "three"; elseif($choice == 4) $str= "four"; $sql = 'SELECT * FROM `poll`;'; $query = mysql_query($sql); while($fetche = mysql_fetch_array($query)){ $id = $fetche['id'];} $sql = 'UPDATE `warzone`.`poll` SET `v '.$str.' = v '.$str.' +1 WHERE `poll`.`id` = \'' .$id.'\' ;'; $query = mysql_query($sql);}} ?> PHP: any help would really be appreciated
while($fetch = mysql_fetch_array($query)) { echo $fetch['question']; ?> <form method='post' action=<? $_SERVER['PHP_SELF'] ?>"> <input type='hidden' name='id' value="<? echo $fetch['id'] ?>"> <input type='radio' name='choice' value='1'><? echo $fetch['one'] ?><br/> <input type='radio' name='choice' value='2'> <? echo $fetch['two']?><br/> <input type='radio' name='choice' value='3'> <? echo $fetch['three']?><br/> <input type='radio' name='choice' value='4'><? echo $fetch['four'] ?><br/> <input type='submit' name='submit' value='Vote!'> </form> <?php } switch($choice) { case 1: $str = 'one'; break; case 2: $str = 'two'; break; case 3: $str = 'three'; break; case 4: $str = 'four'; break; } $sql = 'SELECT * FROM `poll`'; $query = mysql_query($sql); while($fetche = mysql_fetch_array($query)) { $id = $fetche['id']; $sql = 'UPDATE `warzone`.`poll` SET `v '.$str.' = v '.$str.' +1 WHERE `poll`.`id` = \'' .$id.'\''; $query = mysql_query($sql); } ?> Code (markup):
Some tips. First check for POSTED form with: $_SERVER['REQUEST_METHOD'] == "POST" Then check the received parameters ($_POST['id']) if they are nummeric as you want to! Don't use PHP_SELF! it can be used for wrong things!
<?include('connect.php')?> <?php $submit= $_POST['submit']; $id = $_POST['id']; include('admin/config.php'); $choice = $_POST['choice']; $ip = $_SERVER['REMOTE_ADDR']; "<form method='post' action=".$_SERVER['PHP_SELF']." > <input type='hidden' value=" .$ip."></form>"; ?> <? if(isset($submit)){ $sql = 'INSERT INTO `warzone`.`recog` (`id`, `ip`, `pollid`) VALUES (NULL, \'' .$ip. '\', \'' .$id. '\');'; $query = mysql_query($sql); if(!$_POST['choice']){echo "<font color='red'> Please Select an Option </font>";} if($ip == $fetch['ip']){ echo "You already submitted your vote!";} else{$sql ='SELECT * FROM `poll` SELECT * FROM `recog ;'; $query = mysql_query($sql);} while($fetch = mysql_fetch_array($query)){ echo $fetch['question'];?> [HTML]<form method='post' action=<? $_SERVER['PHP_SELF']; ?>" > <input type='hidden' name='id' value="<? echo $fetch['id']; ?>"> <input type='radio' name='choice' value='1'><? echo $fetch['one']; ?><br/> <input type='radio' name='choice' value='2'> <? echo $fetch['two'];?><br/> <input type='radio' name='choice' value='3'> <? echo $fetch['three'];?><br/> <input type='radio' name='choice' value='4'><? echo $fetch['four']; ?><br/> <input type='submit' name='submit' value='Vote!'></form> <? } if($choice == 1) $str= "one"; elseif($choice == 2) $str= "two"; elseif($choice == 3) $str= "three"; elseif($choice == 4) $str= "four"; $sql = 'SELECT * FROM `poll`;'; $query = mysql_query($sql); while($fetche = mysql_fetch_array($query)){ $id = $fetche['id'];} $sql = 'UPDATE `warzone`.`poll` SET `v '.$str.' = v '.$str.' +1 WHERE `poll`.`id` = \'' .$id.'\' ;'; $query = mysql_query($sql);}} ?> PHP:
EricBruggema i didnt really understand what you mean... plus none of the advices worked:S:S i think the problem is with the fetch thing... each time i try to view the script i only see a blank page:S
Could be a few things, turn on error reporting to find out the exact error! This part dont look right: $choice = $_POST['choice'];$ip = $_SERVER['REMOTE_ADDR']; "<form method='post' action=".$_SERVER['PHP_SELF']." ><input type='hidden' value=" .$ip."> </form>"; ?> PHP: The html is not assigned to a variable so Im sure that would give you an error. This doesnt look right either: $sql ='SELECT * FROM `poll` SELECT * FROM `recog ;'; PHP: