我正在尝试在我的留言簿提交表单中添加验证码,但无法使 if(($_POST['code']) == ($_SESSION['code'])) 语句正常工作。请看下面的代码。任何帮助将不胜感激。
if ($_POST['postbtn']){
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$comment = strip_tags($_POST['comment']);
if(($_POST['code']) == ($_SESSION['code'])) {
$code = strip_tags($_POST['code']);
}
if($name && $email && $comment && $code){
$time = date("h:i A");
$date = date("F d, Y");
$ip = $_SERVER['REMOTE_ADDR'];
// add to the database
mysqli_query($con,"INSERT INTO guestbook VALUES (
'', '$name', '$email', '$comment', '$time', '$date', '$ip'
)");
echo "Your post has been added.";
}
else
echo"You did not enter in all the required info.";
}
echo "<form action='./index.php' method='post'>
<table>
<tr>
<td>Name:</td>
<td><input type='text' name='name' style='width: 200px;' /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type='text' name='email' style='width: 200px;' /></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea name='comment' style='width: 197.5px; height: 50px;'>
</textarea></td>
</tr>
<tr>
<td><img src='captcha.php?'/></td>
<td><input type='text' name='code' style='width: 200px;' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='postbtn' value='Post' /></td>
</tr>
</table>
</form>";