Skip to content Skip to sidebar Skip to footer

Undefined Variable, But Variable Is Defined/declared

I am trying to echo data out of a database, however, i am getting the following errors, even though all 3 variables have been. Notice: Undefined variable: fran_phone in /Applicati

Solution 1:

So there's 2 things wrong.

You're clearly trying to learn/switch to prepared statements. mysqli_stmt_execute requires a statement, but you're giving it an mysqli_result object.

Instead of using mysqli_query you need to use mysqli_prepare.

$sql = "SELECT * FROM Franc_dets WHERE Fran_City = ?;";
if ($stmt = mysqli_prepare($dbc, $sql)) {
    mysqli_stmt_bind_param($stmt, "s", $franc_details);
    mysqli_stmt_execute($stmt);

    // Check how many if any rows were returned.$num_rows = mysqli_stmt_num_rows($stmt);

    // Do what you were already doing,// and loop through each returned row.
}

Note that if 0 rows are returned, then you would get the same error(s). As then the variables won't be defined.

Post a Comment for "Undefined Variable, But Variable Is Defined/declared"