stackoverflow stackoverflow - 1 year ago 48
MySQL Question

Passing variable values

May I know how to pass the values from $query if there is values in it. And if it empty, I would still have to pass the variables. I keep getting errors of undefined variable though the variables do exist in the sql database.


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."'");
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;

Answer Source

You need to try some debugging here. For example,

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

Based on the comments, you need to remove that WHERE condition from the query and change it to simply:

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