注册错误时的电子邮件激活链接查询

时间:2014-05-26 23:24:15

标签: php

我正在尝试使这个激活链接php页面似乎无法正常工作。每次执行都会显示错误。

  

警告:mysqli_num_rows()预计在第28行的/home/abc/public_html/abc.com/confirmation-link-validation.php中给出了1个参数,2

  

注意:未定义的变量:第55行的/home/abc/public_html/abc.com/confirmation-link-validation.php中的result2

代码:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

include('connection.php');

// Passkey
$passkey=$_GET['passkey'];

$con=mysqli_connect("localhost","","");
if (!$con) { die("Database connection failed: " . mysqli_error());}
$db_select=mysqli_select_db($con, "");
if (!$db_select) { die("Database selection failed: " . mysqli_error());}

$tbl_name1="temp_users";

// Retrieve data from "temp_users"
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysqli_query($con, $sql1);

// If successfully queried
if($result1){

// Count how many row has this passkey
$count=mysqli_num_rows($con, $result1);   Line 28..

// if passkey found, retrieve data from table "temp_members_db"
if($count==1){

$rows=mysql_fetch_array($result1);
$username=$rows['username'];
$password=$rows['password'];
$name=$rows['name'];
$phone=$rows['phone'];
$email=$rows['email'];
$country=$rows['country'];
$state=$rows['state'];

$tbl_name2="users";

// Insert data "users"
$sql2="INSERT INTO $tbl_name2(username, password, name, phone, email, country, state)VALUES('$username', '$password', '$name', '$phone', '$email', '$country', '$state')";
$result2=mysqli_query($con, $sql2);
}

// if passkey not found
else {
echo "Oops, Something Went Wrong.<br/>Please reregister. Inconvinience is regretted.";
}

// if successfully moved from "temp_users" to "users"
if($result2){ Line 55..

echo "Thank you.<br/>Your account has been activated.<br/><a href=https://abc/owner_login.php>Click Here To Login</a>";

// Delete information "temp_user" with this passkey
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysqli_query($con, $sql3);
}
}
?>

寻求帮助。已添加错误报告。

1 个答案:

答案 0 :(得分:0)

第28行:$count=mysqli_num_rows($result1);

在第28行之后和if($count==1){...之前添加新行$result2 = false;

否则,仅在$result2

时才定义$count == 1