hbalagh Posted August 13, 2007 Share Posted August 13, 2007 I've been searching on the net for a possible solution for this and have been trying all the different options but none seem to work for me i guess because of how my form is set up, but i know there has to be a way for this.... I have it set up so if you have already voted on my poll it will send you to the results page (finally) but when you first vote it still shows the poll again unless you refresh the screen.. and i can't put it in the action= area because all the needed code for the poll is on the poll page here is the code <?php include('database.php'); if(mysql_num_rows(mysql_query("SELECT * FROM ips WHERE ip='".$_SERVER['REMOTE_ADDR']."' LIMIT 1"))) { header("Location: results.php"); exit; } ?> <SCRIPT LANGUAGE="javascript"> function KeepCount() { var NewCount = 0 if (document.form1.a.checked) {NewCount = NewCount + 1} if (document.form1.b.checked) {NewCount = NewCount + 1} if (document.form1.c.checked) {NewCount = NewCount + 1} if (document.form1.d.checked) {NewCount = NewCount + 1} if (document.form1.e.checked) {NewCount = NewCount + 1} if (document.form1.f.checked) {NewCount = NewCount + 1} if (document.form1.g.checked) {NewCount = NewCount + 1} if (document.form1.h.checked) {NewCount = NewCount + 1} if (document.form1.i.checked) {NewCount = NewCount + 1} if (document.form1.j.checked) {NewCount = NewCount + 1} if (document.form1.k.checked) {NewCount = NewCount + 1} if (document.form1.l.checked) {NewCount = NewCount + 1} if (document.form1.m.checked) {NewCount = NewCount + 1} if (document.form1.n.checked) {NewCount = NewCount + 1} if (document.form1.o.checked) {NewCount = NewCount + 1} if (document.form1.p.checked) {NewCount = NewCount + 1} if (document.form1.q.checked) {NewCount = NewCount + 1} if (document.form1.r.checked) {NewCount = NewCount + 1} if (document.form1.s.checked) {NewCount = NewCount + 1} if (document.form1.t.checked) {NewCount = NewCount + 1} if (document.form1.u.checked) {NewCount = NewCount + 1} if (document.form1.v.checked) {NewCount = NewCount + 1} if (document.form1.w.checked) {NewCount = NewCount + 1} if (NewCount == 11) { alert('Please select up to 10 only!') document.form1; return false; } } </SCRIPT> <script type="text/javascript" language="JavaScript"> <!-- function checkCheckBoxes(form1) { if ( form1.a.checked == false && form1.b.checked == false && form1.c.checked == false && form1.d.checked == false && form1.e.checked == false && form1.f.checked == false && form1.g.checked == false && form1.h.checked == false && form1.i.checked == false && form1.j.checked == false && form1.k.checked == false && form1.l.checked == false && form1.m.checked == false && form1.n.checked == false && form1.o.checked == false && form1.p.checked == false && form1.q.checked == false && form1.r.checked == false && form1.s.checked == false && form1.t.checked == false && form1.u.checked == false && form1.v.checked == false && form1.w.checked == false) { alert ('You didn\'t choose any of the options!'); return false; } else { return true; } } //--> </script> <?php //overview $query = "SELECT * FROM polls1 ORDER BY id DESC LIMIT 1"; $rez = mysql_query($query); $row = mysql_fetch_array($rez); $id=$row['id']; print('<table><tr> <td width="380px" align="left" valign="top" bgcolor="#F3F2FD" style="border: 1px solid #000000;"> <h3 style="text-align: center">Museum Park Opinion Poll</h3> <p style="text-align: center">Select up to 10 amenities</p><font size="-2"> <ul style="list-style-type: none; margin:0; padding:0;font-size:12px;"> <form name="form1" id="form1" action="'.$_SERVER['PHP_SELF'].'" method="POST" onsubmit="return checkCheckBoxes(this);"> <li><input type="checkbox" name="a" onClick="return KeepCount()">'.$row['a'].'</li> <li><input type="checkbox" name="b" onClick="return KeepCount()">'.$row['b'].'</li> <li><input type="checkbox" name="c" onClick="return KeepCount()">'.$row['c'].'</li> <li><input type="checkbox" name="d" onClick="return KeepCount()">'.$row['d'].'</li> <li><input type="checkbox" name="e" onClick="return KeepCount()">'.$row['e'].'</li> <li><input type="checkbox" name="f" onClick="return KeepCount()">'.$row['f'].'</li> <li><input type="checkbox" name="g" onClick="return KeepCount()">'.$row['g'].'</li> <li><input type="checkbox" name="h" onClick="return KeepCount()">'.$row['h'].'</li> <li><input type="checkbox" name="i" onClick="return KeepCount()">'.$row['i'].'</li> <li><input type="checkbox" name="j" onClick="return KeepCount()">'.$row['j'].'</li> <li><input type="checkbox" name="k" onClick="return KeepCount()">'.$row['k'].'</li> <li><input type="checkbox" name="l" onClick="return KeepCount()">'.$row['l'].'</li> <li><input type="checkbox" name="m" onClick="return KeepCount()">'.$row['m'].'</li> <li><input type="checkbox" name="n" onClick="return KeepCount()">'.$row['n'].'</li> <li><input type="checkbox" name="o" onClick="return KeepCount()">'.$row['o'].'</li> <li><input type="checkbox" name="p" onClick="return KeepCount()">'.$row['p'].'</li> <li><input type="checkbox" name="q" onClick="return KeepCount()">'.$row['q'].'</li> <li><input type="checkbox" name="r" onClick="return KeepCount()">'.$row['r'].'</li> <li><input type="checkbox" name="s" onClick="return KeepCount()">'.$row['s'].'</li> <li><input type="checkbox" name="t" onClick="return KeepCount()">'.$row['t'].'</li> <li><input type="checkbox" name="u" onClick="return KeepCount()">'.$row['u'].'</li> <li><input type="checkbox" name="v" onClick="return KeepCount()"> Police / First Aid / Hydration Station</li> <li><input type="checkbox" name="w" onClick="return KeepCount()">'.$row['w'].'</li> </ul> <br /><center> <input type="submit" name="action" value="VOTE!"> </center> </form> '); 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; $e = empty($_POST['e']) ? 0 : 1; $f = empty($_POST['f']) ? 0 : 1; $g = empty($_POST['g']) ? 0 : 1; $h = empty($_POST['h']) ? 0 : 1; $i = empty($_POST['i']) ? 0 : 1; $j = empty($_POST['j']) ? 0 : 1; $k = empty($_POST['k']) ? 0 : 1; $l = empty($_POST['l']) ? 0 : 1; $m = empty($_POST['m']) ? 0 : 1; $n = empty($_POST['n']) ? 0 : 1; $o = empty($_POST['o']) ? 0 : 1; $p = empty($_POST['p']) ? 0 : 1; $q = empty($_POST['q']) ? 0 : 1; $r = empty($_POST['r']) ? 0 : 1; $s = empty($_POST['s']) ? 0 : 1; $t = empty($_POST['t']) ? 0 : 1; $u = empty($_POST['u']) ? 0 : 1; $v = empty($_POST['v']) ? 0 : 1; $w = empty($_POST['w']) ? 0 : 1; $x = empty($_POST['x']) ? 0 : 1; if ($a + $b + $c + $d + $e + $f + $g + $h + $i + $j + $k + $l + $m + $n + $o + $p + $q + $r + $s + $t + $u + $v + $w + $x > 0) { $query = "UPDATE results2 SET a = a + %x, b = b + %x, c = c + %x, d = d + %x, e = e + %x, f = f + %x, g = g + %x, h = h + %x, i = i + %x, j = j + %x, k = k + %x, l = l + %x, m = m + %x, n = n + %x, o = o + %x, p = p + %x, q = q + %x, r = r + %x, s = s + %x, t = t + %x, u = u + %x, v = v + %x, w = w + %x, x = x + %x WHERE id = %x"; mysql_query(sprintf($query, $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $x, $id)); mysql_query("INSERT INTO ips (ip) VALUES ('".$_SERVER['REMOTE_ADDR']."')"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64620-solved-redirect-after-form-submit/ Share on other sites More sharing options...
lupld Posted August 13, 2007 Share Posted August 13, 2007 maybe a meta refresh tag? echo "<meta http-equiv=\"refresh\" content=\"2;url=http://webdesign.about.com\">"; 2 (seconds before refresh) ;url=http://webdesign.about.com (url, obviously) is the part that needs refreshed in another frame or iframe or something, cause it should be sent off to php and sent back simulating a refresh anyway... I see a lot of javascript and stuff too though... so it might just be something I haven't come across yet... anyway.. if you want to refresh the page for the user, echo that back.... and as long as you don't have any html on the page where the action is sent to, or the html is after the php, you can use headers too... there's how-to on the top of this forum for them.... Quote Link to comment https://forums.phpfreaks.com/topic/64620-solved-redirect-after-form-submit/#findComment-322186 Share on other sites More sharing options...
hbalagh Posted August 13, 2007 Author Share Posted August 13, 2007 thanks but i just figured it out i just took the php code from the bottom of the of the form and added it to the top of the results page and changed the action of the form to results.php Quote Link to comment https://forums.phpfreaks.com/topic/64620-solved-redirect-after-form-submit/#findComment-322187 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.