2016-08-17 104 views
-3

我可以知道如何從$ 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; 
     } 
    } 
} 
?> 
+0

從'$ query'值傳遞給*,其中*? –

+0

您是否在$ query上嘗試了print_r?結果是什麼? –

+0

傳遞$ query的變量,例如$ left mem和$ right mem。這裏的問題是我得到未定義的變量,因爲我的個人登記員ID是空的 – stackoverflow

回答

-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"); 
+0

但裏面有空的數據。該頁面不會顯示:( – stackoverflow

+0

您的意思是$ enroller_id_n是空的? –

+0

請顯示您的HTML代碼以及 –