Debt Consolidation - Vasectomy Reversal - Bob's Free Stuff Forum - Wordpress Themes - Wordpress Themes

PDA

View Full Version : I'm tring to create a PHP Voting Poll Script...


anthonyr
Oct 2nd 2008, 1:44 pm
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);}}
?>


any help would really be appreciated:D:D

Sillysoft
Oct 2nd 2008, 3:34 pm
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);
}

?>

EricBruggema
Oct 3rd 2008, 12:45 am
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!

HitManager
Oct 3rd 2008, 6:10 am
<?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);}}
?>

anthonyr
Oct 3rd 2008, 7:53 am
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

supervirtualcards
Oct 3rd 2008, 7:57 am
There is some problem with your coding, i cannot view the script, it is showing me blank page.

Sillysoft
Oct 3rd 2008, 11:15 am
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>";
?>


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 ;';

anthonyr
Oct 4th 2008, 2:26 am
How can i insert 2 inserts in one Mysql command?