-3

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.

<?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;
        }
    }
}
?>
stackoverflow
  • 19
  • 1
  • 6
  • pass the values from `$query` to *where*? – Memor-X Aug 17 '16 at 05:45
  • have you tried print_r on $query? What's the result? – Indrasis Datta Aug 17 '16 at 05:45
  • pass the variables of $query for instance $left mem and $right mem. The problem here is Im getting undefined variable because my enroller id in personal is empty – stackoverflow Aug 17 '16 at 05:46
  • 1
    learn about prepares Statements. – Jens Aug 17 '16 at 05:50
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in _meow_ code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Sep 06 '16 at 15:32

1 Answers1

-1

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");
elixenide
  • 44,308
  • 16
  • 74
  • 100
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32