Hi guys, as you can see i'm new to this forum, so first i'll say hi
i'm learning php and stumbled on a problem with mysql
i'm trying to make a poll with mysql
heres the code.
-------------------------------
<?
$db = mysql_connect("localhost","kurei");
mysql_select_db("mysql",$db);
$date = date("d-m-Y");
$ip = $_SERVER["REMOTE_ADDR"];
$sql2 = "SELECT ips FROM ip WHERE date='".$date."' AND ips='".$ip."'";
$result2 = mysql_query($sql2);
$row = mysql_fetch_assoc($result2);
$sql = "select * from poll";
$result = mysql_query($sql);
$array = mysql_fetch_array($result);
$q = $array['q'];
$aa1 = $array['a1'];
$aa2 = $array['a2'];
$aa3 = $array['a3'];
$aa4 = $array['a4'];
$m1 = $array['am1'];
$m2 = $array['am2'];
$m3 = $array['am3'];
$m4 = $array['am4'];
$total = $m1 + $m2 + $m3 + $m4 ;
$p1 = $m1 / $total * 100;
$p2 = $m2 / $total * 100;
$p3 = $m3 / $total * 100;
$p4 = $m4 / $total * 100;
if ($row['ips'] != 0)
{
echo "<table>";
echo "<tr><td width=\"50%\"><b>$q</b></td></tr>";
echo "<br>";
echo "<tr><td width=\"50%\">$aa1</td><td width=\"50%\"><b>$p1 %</font></b></td>";
echo "<br>";
echo "<tr><td width=\"50%\">$aa2</td><td width=\"50%\"><b>$p2 %</font></b></td>";
echo "<br>";
echo "<tr><td width=\"50%\">$aa3</td><td width=\"50%\"><b>$p3 %</font></b></td>";
echo "<br>";
echo "<tr><td width=\"50%\">$aa4</td><td width=\"50%\"><b>$p4 %</font></b></td>";
}
else
{
echo "$q";
echo "<br>";
echo "<form action=\"poll.php\" method=\"post\">";
echo "<input TYPE=\"radio\" NAME=\"answer\" VALUE=\"a1\">";
echo "$aa1";
echo "<br>";
echo "<input TYPE=\"radio\" NAME=\"answer\" VALUE=\"a2\">";
echo "$aa2";
echo "<br>";
echo "<input TYPE=\"radio\" NAME=\"answer\" VALUE=\"a3\">";
echo "$aa3";
echo "<br>";
echo "<input TYPE=\"radio\" NAME=\"answer\" VALUE=\"a4\">";
echo "$aa4";
echo "<br>";
echo "<input type=\"submit\" name=\"submit\" value=\"Vote\">";
echo "</form>";
}
if ($submit) {
$value = $_POST['answer'];
$answers = "$"."$value";
$addip = "INSERT INTO `ip` ( `date` , `ips` ) VALUES ('".$date."', '".$ip."')";
mysql_query($addip);
$addvote = "UPDATE `poll` set '".$value."' = \"5\" WHERE 'q' = '".$q."'";
mysql_query($addvote);
echo "you voted for";
echo $_POST["answer"];
}
?>
----------------------------------------------------------------------
let me explain some of information from the array
a1 = answer one, a2.. you get the drift
aa1 = amount of votes for answer 1, aa2 .. u c
q = question
now seeing i'm still rather new to PHP i cant figure out a way to add 1 to the amount of votes .
$addvote = "UPDATE `poll` set '".$value."' = \"5\" WHERE 'q' = '".$q."'";
mysql_query($addvote);
i need a way to raise $value with 1
i would appreciate if someone could help me. thnx
Probs with Poll + Mysql
Moderator: General Moderators