Jump to content

[SOLVED] Check IP Feature


hbalagh

Recommended Posts

can anyone by chance help with adding an ip feature the below code to prevent people from voting more then once on the following code and what the sql would be for adding the proper ip table to my db

 

thanks so much

 

 

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

Link to comment
https://forums.phpfreaks.com/topic/64546-solved-check-ip-feature/
Share on other sites

Do something like this:

 

<?php

if(!mysql_num_rows(mysql_query("SELECT * FROM ips WHERE ip='".$_SERVER['REMOTE_ADDR']."' LIMIT 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));
	mysql_query("INSERT INTO ips (ip) VALUES ('".$_SERVER['REMOTE_ADDR']."')");
}
}

?>

 

Just create an table called "ips" with a column (varchar) named ip (at least 15 chars long).

 

Orio.

Make sure you put this before any output (echo/print/regular html etc'):

 

header("Location: results.php");

 

 

Orio.

at the very top of the page???  i also have some javascript that i mixed in ... just putting that in will automatically send them to the results page?  im sorry im just still learning and all this helps me to learn and is very appreciated

<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 please')
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 checkboxes!');
	return false;
} else { 	
	return true;
}
}
//-->
</script> 


<?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('<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>

  ');
   
  // 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;
    $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
      ));
    }
  }
  
  print('<a href=results.php>Results</a>
  
<br />	</td></tr></table>
  


  
  ');
?>

Try it this way now:

 

<?php
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(!mysql_num_rows(mysql_query("SELECT * FROM ips WHERE ip='".$_SERVER['REMOTE_ADDR']."' LIMIT 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']."')");
	}
}
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 please')
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 checkboxes!');
	return false;
} else { 	
	return true;
}
}
//-->
</script> 


<?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('<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>

  ');
?>

 

 

Orio.

with that i get the following errors...wouldn't i have to put the  include('database.php'); up higher on the page???

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'museumpa'@'localhost' (using password: NO) in /home/museumpa/public_html/voting/main.php on line 30

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/museumpa/public_html/voting/main.php on line 30

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/museumpa/public_html/voting/main.php on line 30

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'museumpa'@'localhost' (using password: NO) in /home/museumpa/public_html/voting/main.php on line 35

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/museumpa/public_html/voting/main.php on line 35

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'museumpa'@'localhost' (using password: NO) in /home/museumpa/public_html/voting/main.php on line 36

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/museumpa/public_html/voting/main.php on line 36

 

Warning: Cannot modify header information - headers already sent by (output started at /home/museumpa/public_html/voting/main.php:30) in /home/museumpa/public_html/voting/main.php on line 39

 

 

 

errors are..

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'museumpa'@'localhost' (using password: NO) in /home/museumpa/public_html/voting/main.php on line 30

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/museumpa/public_html/voting/main.php on line 30

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/museumpa/public_html/voting/main.php on line 30

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'museumpa'@'localhost' (using password: NO) in /home/museumpa/public_html/voting/main.php on line 35

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/museumpa/public_html/voting/main.php on line 35

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'museumpa'@'localhost' (using password: NO) in /home/museumpa/public_html/voting/main.php on line 36

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/museumpa/public_html/voting/main.php on line 36

 

Warning: Cannot modify header information - headers already sent by (output started at /home/museumpa/public_html/voting/main.php:30) in /home/museumpa/public_html/voting/main.php on line 39

 

 

the code i had that was giving me the above errors is below

 

 

<?php
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(!mysql_num_rows(mysql_query("SELECT * FROM ips WHERE ip='".$_SERVER['REMOTE_ADDR']."' LIMIT 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']."')");
	}
}
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 please')
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 checkboxes!');
	return false;
} else { 	
	return true;
}
}
//-->
</script> 


<?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('<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>

  ');
?>

 

 

The code i had before that works fine w/o errors is below, but I want to add the ip feature to it to check to see if the person has voted before then if they have it sends to results.php

 

 

<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 please')
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 checkboxes!');
	return false;
} else { 	
	return true;
}
}
//-->
</script> 


<?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('<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>

  ');
   
  // 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;
    $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
      ));
    }
  }
  
  print('<a href=results.php>Results</a>
  
<br />	</td></tr></table>
  


  
  ');
?>

 

the  include('database.php');  ??? if so that is what i was asking about but was told my db wasn't set up right....

 

im still very new to all this which is why i was asking if someone could just alter the code to include the ip check with a if statement that if they have already voted it would send them to the resutls.php page...

which is why i was asking if someone could just alter the code to include the ip check with a if statement that if they have already voted it would send them to the resutls.php page...

 

Maybe... but that won't teach you anything.

 

f so that is what i was asking about but was told my db wasn't set up right....

 

Sorry... I didn't read that part. Yes, include('database.php') needs to be before any attempts to actually use the database.

which is why i was asking if someone could just alter the code to include the ip check with a if statement that if they have already voted it would send them to the resutls.php page...

 

Maybe... but that won't teach you anything.

 

f so that is what i was asking about but was told my db wasn't set up right....

 

Sorry... I didn't read that part. Yes, include('database.php') needs to be before any attempts to actually use the database.

 

I moved the database.php at the top of the page and still got an error along with the headers already sent error... and yes i would learn from the code from studying it and looking over it

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.