2014-02-12 83 views
0

這是我的查詢註冊表頁面,但由於某種原因,PHP中的驗證碼不起作用。請幫忙。這是我的學校工作所必需的。驗證碼不在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; hbsdchjnosdyhfsidufynhisdgfltbugisduafnhsldufgsidflgsidnfuhsdifusgdifudsgainfusgdafiusnfhnsdgfisudanfgilsdufghs; 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 <[email protected]>"; 


$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"; 
} 
?> 
+1

「_code in php is working_」你能詳細說一下嗎? – csmckelvey

+0

驗證以檢查字段是否已輸入,並直接進入操作。它只是不檢查領域。 – user2836146

回答

0

我只是試過你的代碼,它對我來說工作得很好。

在窗體的action屬性您引用的文件signup_ac.php

form name="form1" action="signup_ac.php" method="post"> 

驗證碼必須是文件signup_ac.php英寸在你的情況下,我假設signup_ac.php是包含你在上面發佈的代碼的文件。你確定沒有輸入錯別字或錯誤的名字嗎?

沒有更好的描述我不知道還有什麼建議。