hbalagh Posted August 11, 2007 Share Posted August 11, 2007 Hello I have a poll script that I am in desperate need to let the users have more then one choice to the poll when they are voting...here is the original code below all i know is i have to change the type from radio to checkbox.. but other then that i'm totally lost, can anyone please give me the exact code i would need to change this... I am still a real newbie as far as this stuff goes... Thanks alot <?php //overview include('database.php'); $query="SELECT * FROM polls1 ORDER BY id DESC LIMIT 1"; $rez=mysql_query($query); $row=mysql_fetch_array($rez); $id=$row['id']; print " <center> <form action=\"".$_SERVER['php_self']."\" method=\"POST\"> <br>\"".$row['quest']."\"<br /> <br>\"".$row['a']."\"<input type=\"radio\" name=\"a\"><br /> <br>\"".$row['b']."\"<input type=\"radio\" name=\"b\"><br /> <br>\"".$row['c']."\"<input type=\"radio\" name=\"c\"><br /> <br>\"".$row['d']."\"<input type=\"radio\" name=\"d\"><br /> <input type=\"submit\" name=\"action\" value=\"Send!\"> </form> </center> "; if(isset($_POST['action'])) { $a=$_POST['a']; $b=$_POST['b']; $c=$_POST['c']; $d=$_POST['d']; if(isset($a)) { $query1="SELECT a FROM results2 ORDER BY id DESC LIMIT 1"; $rez1=mysql_query($query1); $row=mysql_fetch_array($rez1); $row1=$row['a'] + 1; $query2="UPDATE results2 SET a='$row1' WHERE id = $id"; $rez2=mysql_query($query2); } else if(isset($b)) { $query1="SELECT b FROM results2 ORDER BY id DESC LIMIT 1"; $rez1=mysql_query($query1); $row=mysql_fetch_array($rez1); $row1=$row['b'] + 1; $query2="UPDATE results2 SET b = '$row1' WHERE id = $id"; $rez2=mysql_query($query2); } else if(isset($c)) { $query1="SELECT c FROM results2 ORDER BY id DESC LIMIT 1"; $rez1=mysql_query($query1); $row=mysql_fetch_array($rez1); $row1=$row['c'] + 1; $query2="UPDATE results2 SET c = '$row1' WHERE id = $id"; $rez2=mysql_query($query2); } else if(isset($d)) { $query1="SELECT d FROM results2 ORDER BY id DESC LIMIT 1"; $rez1=mysql_query($query1); $row=mysql_fetch_array($rez1); $row1=$row['d'] + 1; $query2="UPDATE results2 SET d = '$row1' WHERE id = $id"; $rez2=mysql_query($query2); } } print "<a href=results.php>Results</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/64348-changing-from-single-to-multiple-select/ Share on other sites More sharing options...
gurroa Posted August 11, 2007 Share Posted August 11, 2007 <?php //overview include('database.php'); $query = "SELECT * FROM polls1 ORDER BY id DESC LIMIT 1"; $rez = mysql_query($query); $row = mysql_fetch_array($rez); $id=$row['id']; print('<center> <form action="'.$_SERVER['PHP_SELF'].'" method="POST"> <br>"'.$row['quest'].'"<br /> <br>"'.$row['a'].'"<input type="checkbox" name="a"><br /> <br>"'.$row['b'].'"<input type="checkbox" name="b"><br /> <br>"'.$row['c'].'"<input type="checkbox" name="c"><br /> <br>"'.$row['d'].'"<input type="checkbox" name="d"><br /> <br /> <input type="submit" name="action" value="Send!"> </form> </center> '); // you can use this code to write one result from radio checks too. // because in that case only one value will be filled if(isset($_POST['action'])) { $a = empty($_POST['a']) ? 0 : 1; $b = empty($_POST['b']) ? 0 : 1; $c = empty($_POST['c']) ? 0 : 1; $d = empty($_POST['d']) ? 0 : 1; if ($a + $b + $c + $d > 0) { $query = "UPDATE results2 SET a = a + %d, b = b + %d, c = c + %d, d = d + %d WHERE id = %d"; mysql_query(sprintf($query, $a, $b, $c, $d, $id )); } } print('<a href=results.php>Results</a>'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64348-changing-from-single-to-multiple-select/#findComment-320917 Share on other sites More sharing options...
hbalagh Posted August 11, 2007 Author Share Posted August 11, 2007 thank you so much...it worked like a charm....now can anyone by chance help with adding an ip feature to it to prevent people from voting more then once and what the sql would be for adding the proper ip table to my db thanks so much again Quote Link to comment https://forums.phpfreaks.com/topic/64348-changing-from-single-to-multiple-select/#findComment-321300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.