I’ve got just a quick little poll and a query to check and see if the IPaddress is already in the table to know if someone has already voted. I have the table created already and it works.
My question is with the if else statement it is not working. I am trying to make it
if ip address is in the table show string
else show poll
$ip=$_SERVER['REMOTE_ADDR'];
include("../db/config.php");
include("../db/opendb.php");
$result = mysql_query("SELECT * FROM Poll WHERE ip='$ip'");
if ($result==$ip) {
echo "Thank you for voting.";
} else {
echo "<form action=logvote.php method=post>" .
"<input type=radio name=ans value=ans1> Answer1<br>" .
"<input type=radio name=ans value=ans2> Answer2<br>" .
"<input type=radio name=ans value=ans3> Answer3<br>" .
"<input type=radio name=ans value=ans4> Answer4<br>" .
"<input type=submit value=Submit>";
echo "<input type=hidden name=ip value=";
echo "$ip>";
echo "</form>";
include("../db/closedb.php");
}
Thanks in advance.
Your code should be:
mysql_query() returns a reference not a string.
Also, using ip in the SELECT statement will speed up your code.