PHP IF消息未被打印

时间:2017-12-15 15:51:52

标签: php mysql forms

我有一个带有电子邮件确认的注册脚本,它的工作几乎没问题。 用户信息首先从表单发送到“临时”表,当他跟随电子邮件确认链接时,信息从“临时”表变为“印度”表,即最终目的地。

确认链接是名为“confirmation.php”的文件。

虽然代码是将数据从一个表发送到另一个表,但它不会打印消息“Obrigado,o seu registo foi validado。”,葡萄牙语为“谢谢,您的注册现已经过验证”。我做错了什么?

谢谢!

Confirmation.php

<?php
include_once ('config.php');

$confirm_code = $_GET["confirm_code"];

$sql1 = mysqli_query($conn, "SELECT * FROM temp WHERE confirm_code = '$confirm_code'");
$result1= mysqli_fetch_array($sql1, MYSQLI_ASSOC);

if(mysqli_num_rows($sql1) == 1) {
    $query = mysqli_query($conn, "INSERT INTO india (confirm_code, name, password, email) SELECT confirm_code, name, password, email FROM temp WHERE confirm_code = '$confirm_code'");

    if($query) {
        $del = mysqli_query($conn, "DELETE FROM temp WHERE confirm_code = '$confirm_code'");
        if($del) {
            $msg = "Obrigado, o seu registo foi validado.";
        }    
    }   
} else {
    $msg2 = "Erro no registo";
}   
$conn->close();
?>

2 个答案:

答案 0 :(得分:1)

您应该使用结果变量代替if(mysqli_num_rows($sql1) == 1) {if(mysqli_num_rows($result1) == 1) {

请同时使用参数化查询,如How can I prevent SQL injection in PHP?

中所述

答案 1 :(得分:0)

尝试mysqli_query($conn, "DELETE FROM temp WHERE confirm_code = '$confirm_code'");

在这样的if条件中:(你想错过打印我认为)

if(mysqli_query($conn, "DELETE FROM temp WHERE confirm_code = '$confirm_code'"))`
{ 
  $msg = "Obrigado, o seu registo foi validado.";
 echo $msg;
}