if (! empty ( $fname ) && ! empty ( $lname )) {
$query5 = "select * from " . $db_prefix . "customer_det where (fname = '" . $fname . "' and lname = '" . $lname . "')";
$result5 = $mysqli->query ( $query5, MYSQLI_STORE_RESULT ) or die ( mysql_error () );
} else {
$query5 = "select * from " . $db_prefix . "customer_det where phone = '" . $phone . "'";
$result5 = $mysqli->query ( $query5, MYSQLI_STORE_RESULT ) or die ( mysql_error () );
}
while ($row=$result5->fetch_assoc) {
$uid = $row['id'];
$visits = $row['visits'];
}
var_dump($uid);
var_dump($visits);
var_dump($result5);
var_dump($fname);
var_dump($lname);
I’m not sure where I’m going wrong here. I run both of those queries in the phpMyAdmin SQL query box and it returns a row set. Then when I run it in PHP, and var_dump the variables, $uid returns NULL as well as $visits. Here’s the var dump:
NULL NULL object(mysqli_result)#4 (5) { ["current_field"]=> int(0) ["field_count"]=> int(34) ["lengths"]=> NULL ["num_rows"]=> int(1) ["type"]=> int(0) } string(6) "Wesley" string(6) "Snipes"
Any advice would be great.
When you’re calling
fetch_assoc(), you’re forgetting the parentheses:Should be:
Because of this, the loop is never entered and
$uidand$visitsaren’t being set (so they’re stillnull).