I'm tring to create a PHP Voting Poll Script...

Discussion in 'PHP' started by anthonyr, Oct 2, 2008.

  1. #1
    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:D:D
     
    anthonyr, Oct 2, 2008 IP
  2. Sillysoft

    Sillysoft Active Member

    Messages:
    177
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    
    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):
     
    Sillysoft, Oct 2, 2008 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    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!
     
    EricBruggema, Oct 3, 2008 IP
  4. HitManager

    HitManager Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
      <?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:
     
    HitManager, Oct 3, 2008 IP
  5. anthonyr

    anthonyr Peon

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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
     
    anthonyr, Oct 3, 2008 IP
  6. supervirtualcards

    supervirtualcards Banned

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There is some problem with your coding, i cannot view the script, it is showing me blank page.
     
    supervirtualcards, Oct 3, 2008 IP
  7. Sillysoft

    Sillysoft Active Member

    Messages:
    177
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #7
    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:
     
    Sillysoft, Oct 3, 2008 IP
  8. anthonyr

    anthonyr Peon

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How can i insert 2 inserts in one Mysql command?
     
    anthonyr, Oct 4, 2008 IP