| | |
need help - survey voting
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2009
Posts: 11
Reputation:
Solved Threads: 0
i'm having problem with survey script and voting function. can anyone please help me out.. the script only accept the last question's answer and update the database = acount+1.
script to dislay survey:
voting script:
please help.....
script to dislay survey:
PHP Syntax (Toggle Plain Text)
<?php echo "<form action='vote.php' method=post> <table width='300' border='0' cellspacing='0' cellpadding='0' align='center'>"; $query1 = "SELECT * FROM questions"; $result1 = mysql_query($query1)or die("ERROR: $query.".mysql_error()); $num_row=mysql_num_rows($result1); $i=1; while($i<$num_row){ while ($row1 = mysql_fetch_array($result1)) { $qid = $row1['qid']; $qtitle = $row1['qtitle']; $query2 = "SELECT * FROM answers WHERE qid='$qid'"; $result2 = mysql_query($query2) or die("ERROR: $query.".mysql_error()); echo "<tr> <td width='300' align='left'><p>".$i.". ".$qtitle."</p></td> </tr>"; while ($row2 = mysql_fetch_array($result2)) { $aid = $row2['aid']; $atitle = $row2['atitle']; echo "<tr> <td width='300' align='left'><input type = radio name =aid value = '".$aid."'><font>".$atitle."</font></input><br></p></td> </tr>"; } echo "<input type = hidden name = qid value = '".$qid."'>"; echo "<br />"; $i++; } } echo "<td><br><br></td><tr> <td width='300' align='center'><input type = submit name = submit value = 'Submit'></td> </tr> </table> </form>"; } } // close connection mysql_close(); ?>
voting script:
PHP Syntax (Toggle Plain Text)
<?php if (isset($_COOKIE) && !empty($_COOKIE)) { if ($_COOKIE['lastpoll'] && $_COOKIE['lastpoll'] == $_POST['qid']) { echo '<script>alert("You have already voted. Thank You !!!");</script>'; echo '<script>location.replace("trysurvey.php");</script>'; exit(); } } // set cookie setCookie('lastpoll', $_POST['qid'], time() + 2592000); if (isset($_POST['submit'])) { if (!isset($_POST['aid'])) { echo '<script>alert("Please select one of the available choices.");</script>'; echo '<script>history.back(1);</script>'; } else{ require_once('config.php'); $aid=$_POST['aid']; $qid=$_POST['qid']; // update vote counter $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid' AND qid = '$qid'"; $result = mysql_query($query) or die("ERROR: $query. ".mysql_error()); } // close connection mysql_close(); // print success message echo '<script>alert("Your have successfully voted.");</script>'; echo '<script>location.replace("trysurvey.php");</script>'; } else { echo '<script>alert("Unable to submit your Vote. Please try again !!!");</script>'; echo '<script>history.back(1);</script>'; } ?>
please help.....
![]() |
Similar Threads
- News Story: Do IT Survey Results Make You Reach for the Hemlock? (Tech / IT Consultant Job Offers)
- survey for school grads... Another question (PHP)
- trying to make a survey for school yearbook, need help (PHP)
- News Story: Linux Foundation Desktop Survey Results (Window and Desktop Managers)
- News Story: Certification Survey for 2006 is in. (Windows Software)
- Online voting !! (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: session variable problem
- Next Thread: refresh page one time only..
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop parse paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source space speed sql structure subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web white xml youtube





