problem creating poll using mysql
Moderator: General Moderators
problem creating poll using mysql
i keep getting this error
any ideas?
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND voteip='127.0.0.1'' at line 1
- someone else said this
your variable $poll_id is empty. try filling in a number for it.
how do i do that can you explain please?
any ideas?
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND voteip='127.0.0.1'' at line 1
- someone else said this
your variable $poll_id is empty. try filling in a number for it.
how do i do that can you explain please?
code posted
this is the code
think the error is in the select statement.
think the error is in the select statement.
Code: Select all
$pollid=$_GET["pollid"];
$vote=$_POST["vote"];
$datestamp=date("Y-m-d H:i:s", time());
$ip=getenv("REMOTE_ADDR");
$ref=getenv("HTTP_REFERER");
$ref=explode("?", $ref);
$sql_vote="SELECT * FROM pollstats WHERE pollid=$pollid AND voteip='$ip'";
$res_vote=mysql_query($sql_vote) or die(mysql_error());
$num_vote=mysql_num_rows($res_vote);
if (!$vote) {
$url=$ref[0]."?pollerr=Something+went+wrong+with+your+vote.";
header("Location: $url");
}
elseif ($num_vote) {
$url=$ref[0]."?pollerr=You+seem+to+have+voted+before.";
header("Location: $url");
}
else {
$sql_vote2="UPDATE poll2 SET votes$vote=votes$vote+1 WHERE pollid=$pollid";
$sql_vote3="INSERT INTO pollstats(pollid, vote, datestamp, voteip) VALUES($pollid, $vote, '$datestamp', '$ip')";
$res_vote2=mysql_query($sql_vote2) or die(mysql_error());
$res_vote3=mysql_query($sql_vote3) or die(mysql_error());
$url=$ref[0];
header("Location: $url");
}
?>-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Example:
Code: Select all
// <snip>
$sql_vote="SELECT * FROM pollstats WHERE pollid=$pollid AND voteip='$ip'";
echo $sql_vote;
exit;Note the "pollid= AND" ?mike08 wrote:this is the error i got when i just put that code in you told me too.
what does this mean please?
SELECT * FROM pollstats WHERE pollid= AND voteip='127.0.0.1'
"Aha!" you should think, "The $pollid=$_GET["pollid"]; in my code above must be malfunctioning!".
A tip is to check if:
Code: Select all
// this row...
$pollid=$_GET["pollid"];
// perhaps should look like...
$pollid=$_POST["pollid"];Try changing this:
to this:
Some ' s might do the job sometimes 
Code: Select all
<?php
$sql_vote="SELECT * FROM pollstats WHERE pollid=$pollid AND voteip='$ip'";
?>to this:
Code: Select all
<?php
$sql_vote="SELECT * FROM pollstats WHERE pollid='$pollid' AND voteip='$ip'";
?>