我已经在PHP中创建了一个在线调查,只有一个例外,它可以正常工作。
我希望我的选民仅限一票,我决定用他们的IP地址跟踪他们。不幸的是,我提出的代码似乎根本不起作用:
<?php
session_start();
require('execute.php');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$track = ($_POST['track']);
$address = ($_SERVER['REMOTE_ADDR']);
if(empty($_POST['track']))
{
echo 'Please select one of the tracks';
}
else
{
$t = mysqli_real_escape_string($dbc, trim ($track));
}
if(empty($_SERVER['REMOTE_ADDR']))
{
echo '';
}
else
{
$i = mysqli_real_escape_string($dbc, trim ($address));
}
if(!empty($_POST['track']))
{
$q = "SELECT track_id FROM track WHERE address = '$i'";
$r = mysqli_query($dbc, $q);
if(mysqli_num_rows($r) != 0)
{
echo 'You have already voted';
}
else
{
$q = "INSERT INTO track (track, ip_address) VALUES ('$t', '$i')";
$r = mysqli_query($dbc, $q);
echo 'Thank you for voting';
mysqli_close($dbc);
}
}
}
?>
我遇到问题的地方是
$q = "SELECT track_id FROM track WHERE address = '$i'";
IP记录保存在数据库中,但条件无法正常执行,因此用户仍可多次投票。
欢迎任何建议。
此致
亚切克