-1

Please keep in mind that i'm totally new to the OOP concept and what i have been trying to do is retrieve data from mysql database and echo the result. yes as simple as that but i have getting different errors so here is the function that should return the result

function fetchUserByEmail($email=NULL)
{
    if($email!=NULL) {
        $column = "email";
        $data = $email;
    }
    global $mysqli,$db_table_prefix; 
    $stmt = $mysqli->prepare("SELECT 
        id,
        user_name,
        display_name,
        password,
        email,
        activation_token,
        last_activation_request,
        lost_password_request,
        active,
        title,
        sign_up_stamp,
        last_sign_in_stamp
        FROM ".$db_table_prefix."users
        WHERE
        $column = ?
        LIMIT 1");
        $stmt->bind_param("s", $data);

    $stmt->execute();
    $stmt->bind_result($id, $user, $display, $password, $email, $token, $activationRequest, $passwordRequest, $active, $title, $signUp, $signIn);
    while ($stmt->fetch()){
        $row = array('id' => $id, 'user_name' => $user, 'display_name' => $display, 'password' => $password, 'email' => $email, 'activation_token' => $token, 'last_activation_request' => $activationRequest, 'lost_password_request' => $passwordRequest, 'active' => $active, 'title' => $title, 'sign_up_stamp' => $signUp, 'last_sign_in_stamp' => $signIn);
    }
    $stmt->close();
    return ($row);
}

what i need to know is exactly how am i going to call the result in a html tags

here is my attempt:

$email = mysql_real_escape_string($_POST['email']);
fetchUserByEmail($email);
    ?><ul>
        <div style="background-color:#EEEEEE" class="content">
            <li>
            <h2><?php echo  $row['id'];?></h2>

i get the Notice: Undefined variable: ERROR

1 Answers1

0

You see, the local $row variable inside the function is lost when it ends its execution. As this line <h2><?php echo $row['id'];?></h2> is outside fetchUserByEmail(), then $row will be undefined by that moment.

You can assign the result of your function to $row variable: $row = fetchUserByEmail($email)

Roberto Maldonado
  • 1,585
  • 14
  • 27