传递变量值

时间:2016-08-17 05:43:06

标签: php mysql mysqli

如果有值,我可以知道如何从$ query传递值。如果它是空的,我仍然必须传递变量。虽然变量确实存在于sql数据库中,但我仍然会收到未定义变量的错误。

<?php
include("dbconnect.php");
include("header.php");

if (isset($_POST['btn'])) {
    $uname        = $MySQLi_CON->real_escape_string(trim($_POST['user_name']));
    $email        = $MySQLi_CON->real_escape_string(trim($_POST['user_email']));
    $upass        = $MySQLi_CON->real_escape_string(trim($_POST['password']));
    $enroller_id_n = $MySQLi_CON->real_escape_string(trim($_POST['enroller_id_n']));        
    $enrolled_id_n=  $MySQLi_CON->real_escape_string(trim($_POST['enrolled_id_n'])); 
    $direction = $MySQLi_CON->real_escape_string(trim($_POST['direction'])) ;
    $new_password = password_hash($upass, PASSWORD_DEFAULT);
    $query = $MySQLi_CON->query("select * from personal where enroller_id='".$enroller_id_n."'");
    if($query){
        while ($row = $query->fetch_array()) {
            $enroller_id3 = $row['enroller_id'];
            $left_mem     = $row['left_mem'];
            $right_mem    = $row['right_mem'];
            $test         = "left_mem";
            $test2        = "right_mem";
            $direc        = $direction;
        }
    }
}
?>

1 个答案:

答案 0 :(得分:-1)

你需要在这里尝试一些调试。例如,

var_dump($enroller_id_n); // Check if the variable is not empty

$query = $MySQLi_CON->query("select * from personal where enroller_id='".$enroller_id_n."'") or die($MySQLi_CON->error);

$row = $query->fetch_array(MYSQLI_ASSOC);

echo "<pre>";
print_r($row);  // Check your result array

根据评论,您需要从查询中删除该WHERE条件并将其更改为:

$query = $MySQLi_CON->query("select * from personal");