验证PHP不工作?

时间:2013-06-12 03:04:31

标签: php validation email

以下是我网站的电子邮件验证码。

发送给用户电子邮件的验证网址如下: http://www.mywebsite.com/valid.php?confr=2774405&userid=2

额外备注

1)key是我的数据库中的一个列,它在注册时获得随机值。

2)如果$verify == 1password_in_db=== user_entered_password,则登录将在登录页面中进行。

<?php

    include 'connect.php';

    $query = mysql_query("SELECT verify,key FROM users WHERE id = '$_GET['userid']'");
    $details = mysql_fetch_assoc($query);
    $verify = $details['verify'];
    $confirm2 = $details['key'];

    if($verify == "1") {
        echo "Link Expired . Go to our login page :";
    } else {
        if (isset($_GET["confr"]) && isset($_GET["userid"])) {
            $confirm1 =$_GET["confr"];

            if($confirm1 == $confirm2) {
                mysql_query("INSERT INTO users (`verify`) VALUES ('1') WHERE id = '$_GET["userid"]' ;");
                echo "Thank You For Registering with us . Go to your LOGIN PAGE Here ";
            } else {
                echo "Invalid link ";
                echo "Go to your LOGIN PAGE Here ";
            }
        } //  of if isset
    } // of  else part
?>

connect.php的代码

<?php
    mysql_connect("host", "username", "pass");  //connects to the server
    mysql_select_db("database_name");  //selects the database
?>

问题是它给了我一个空白的屏幕。

3 个答案:

答案 0 :(得分:0)

我相信错误在于sql

当我使用“WHERE”语句时,我总是将其定义为变量,请尝试使用

<?php
include 'connect.php';
$user_id = $_GET["userid"];
$query = mysql_query("SELECT verify,key FROM users WHERE id = '$user_id'");
$details = mysql_fetch_assoc($query);
$verify = $details['verify'];
$confirm2 = $details['key'];
if($verify == "1"){
echo "Link Expired . Go to our login page :";
}
else{
if (isset($_GET["confr"]) && isset($_GET["userid"]))
{
$confirm1 =$_GET["confr"];
if($confirm1 == $confirm2){

mysql_query("INSERT INTO users (`verify`) VALUES ('1') WHERE id = '$user_id'");

echo "Thank You For Registering with us . Go to your LOGIN PAGE Here ";
}
else {
echo "Invalid link ";
echo "Go to your LOGIN PAGE Here ";
}
} //  of if isset
} // of  else part

?>

另外,插入sql

中有一个半冒号

答案 1 :(得分:0)

试试这个.......

<?php
include 'connect.php';

$user_id = $_GET["userid"];
$query = mysql_query("SELECT verify,key FROM users WHERE id = '$user_id'"); 
   while ($details = mysql_fetch_assoc($query)){ 
      $verify = $details['verify']; 
      $confirm2 = $details['key']; 
    }
if($verify == "1"){
    echo "Link Expired . Go to our login page :";
}
 else{
   if (isset($_GET["confr"]) && isset($_GET["userid"]))
 {
   $confirm1 =$_GET["confr"];
   if($confirm1 == $confirm2){

mysql_query("INSERT INTO users (`verify`) VALUES ('1') WHERE id = '$user_id'");

echo "Thank You For Registering with us . Go to your LOGIN PAGE Here ";
}
else {
echo "Invalid link ";
echo "Go to your LOGIN PAGE Here ";
    }
  } //  of if isset
} // of  else part

?>

答案 2 :(得分:0)

注意:insert语句无处可去 - 只要你不使用“insert into select ...”

http://dev.mysql.com/doc/refman/5.1/de/insert.html