这是我的查询注册表页面,但由于某种原因,php中的验证码无效。请帮忙。这是我学校工作所必需的。
<head>
<title>
Inquiry Form
</title>
</head>
<body>
<br>
<p>
<h1 style="color:blue; align:center;">
INQUIRY FORM
</h1>
</p>
<br>
<br>
<?php
$companynameErr = $emailErr = $phonenumberErr = $roadnameErr = $cityErr = $postcodeErr ="";
$companyname = $email = $phonenumber = $roadname = $city = $postcode = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["companyname"]))
{$companynameErr = "Company name is required";}
else
{$companyname = test_input($_POST["companyname"]);
}
if (empty($_POST["email"]))
{$emailErr = "Email is required";}
else
{
$email = test_input($_POST["email"]);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
$emailErr = "Invalid email format";
}
}
if (empty($_POST["phonenumber"]))
{$phonenumberErr = "Phone number is required";}
else
{$phonenumber = test_input($_POST["phonenumber"]);
}
if (empty($_POST["roadname"]))
{$roadnameErr = "Road name is required";}
else
{$roadname = test_input($_POST["roadname"]);
}
if (empty($_POST["city"]))
{$cityErr = "City is required";}
else
{$city = test_input($_POST["city"]);
}
if (empty($_POST["postcode"]))
{$postcodeErr = "Postcode is required";}
else
{$postcode = test_input($_POST["postcode"]);
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form name="form1" action="signup_ac.php" method="post">
<table border="1" style="width:30%; align: center;">
<tr>
<td style="width:50%; align:center;">
<h3>
Company name:
</h3>
</td>
<td>
<input type="text" name="companyname" size=60>
<span class="error">* <?php echo $companynameErr;?></span>
</td>
</tr>
<tr>
<td style="width:50%; align:center;">
<h3>
Telephone number:
</h3>
</td>
<td>
<input type="number" name="phonenumber" size=60>
<span class="error">* <?php echo $phonenumberErr;?></span>
</td>
</tr>
<tr>
<td style="width:50%; align:center;">
<h3>
Email:
</h3>
</td>
<td>
<input type="text" name="email" size=60>
<span class="error">* <?php echo $emailErr;?></span>
</td>
</tr>
<tr>
<td style="width:50%; align:center;">
<h3>
Road / Street name:
</h3>
</td>
<td>
<input type="text" name="roadname" size=60>
<span class="error">* <?php echo $roadnameErr;?></span>
</td>
</tr>
<tr>
<td style="width:50%; align:center;">
<h3>
City:
</h3>
</td>
<td>
<input type="text" name="city" size=60>
<span class="error">* <?php echo $cityErr;?></span>
</td>
</tr>
<tr>
<td style="width:50%; align:center;">
<h3>
Postcode:
</h3>
</td>
<td>
<input type="text" name="postcode" size=60>
<span class="error">* <?php echo $postcodeErr;?></span>
</td>
</tr>
<tr>
<td colspan="2" align=center>
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
我的signup_ac.php包含(抱歉这个,但是需要更多详细信息,我不知道该写什么,所以请删除这个支架ladfhsdufbghisafg; hbsdchjnosdyhfsidufynhisdgfltbugisduafnhsldugsgsdflgsidnfuhsdifusgdifudsgainfusgdafiusnfhnsdgfisudanfgilsdufghs; dufhnilsdkufhdikfungsisdjfylisaf.m,uhsl):
<?php
include('config.php');
$tbl_name=temp_members_db;
$confirm_code=md5(uniqid(rand()));
$companyname=$_POST['companyname'];
$email=$_POST['email'];
$phonenumber=$_POST['phonenumber'];
$roadname=$_POST['roadname'];
$city=$_POST['city'];
$postcode=$_POST['postcode'];
$sql="INSERT INTO $tbl_name(confirm_code, companyname, email, phonenumber, roadname, city, postcode)VALUES('$confirm_code', '$companyname', '$email', '$phonenumber', '$roadname', '$city', '$postcode')";
$result=mysql_query($sql);
if($result){
$to=$email;
$subject="Your confirmation link here";
$header="from: SK Azmayeen Reshad <skazmayeen.reshad007@hotmail.com>";
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://localhost/myphpproject/Controlled/confirmation.php?passkey=$confirm_code";
$sentmail = mail($to,$subject,$message,$header);
}
else {
echo "Not found your email in our database";
}
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>
答案 0 :(得分:0)
我刚试过你的代码,它对我来说很好。
在表单的action
属性中,您引用了文件 signup_ac.php :
form name="form1" action="signup_ac.php" method="post">
验证码必须位于 signup_ac.php 文件中。在你的情况下,我假设signup_ac.php是包含你在上面发布的代码的文件。你确定没有输入拼写错误或输入错误的名字吗?
如果没有更好的描述,我不确定还有什么建议。