Why mysqli_stmt_bind_result Failing To Yield Results Properly ?

sunny_pro

New member
Joined
Jun 18, 2017
Messages
86
Points
0
Folks, the following code is supposed to pull results from my db tbl.
It manages to pull some column data while fails on others. Error reporting on. I have not made any errors on the $variable naming. Nor, any errors on column naming. I get no error.
But for some reason, the script manages to pull some column data while others not. What is the mystery behind this new problem ?
For proof of my claim, check the 3rd ELSE that looks like the following by looking at my comment in the code:

PHP:
else
	{
		//FOLLOWING ECHOES CHECK WHETHER $RESULTS GOT PULLED OR NOT
		echo 'Results yielded $id:'; echo "$id<br>"; //THIS IS GETTING YIELDED
		echo 'Results yielded $date_and_time:'; echo "$date_and_time<br>"; //WHY IS THIS FAILING TO GET YIELDED ?
		echo 'Results yielded $recipient_username:'; echo "$recipient_username<br>"; //THIS IS GETTING YIELDED
		echo 'Results yielded $sender_username:'; echo "$sender_username<br>"; //WHY IS THIS FAILING TO GET YIELDED ?
		echo 'Results yielded $message:'; echo "$message<br>"; //WHY IS THIS FAILING TO GET YIELDED ?
	}
My point is, it should either work 100% or not work atall and show errors. And not manage to pull some column data while others not. Strange!

Full Code:
PHP:
<?php 

//Required PHP Files. 
include 'config.php'; 
include 'header.php'; 

//Check if User is already logged-in or not. Get the login_check() FUNCTION to check. 
if (login_check() === FALSE) 
{
	//Redirect User to Log-in Page after 2 secs. 
	header("refresh:2; url=login.php"); 
	exit(); 
} 
else 
{ 
	$user = $_SESSION["user"]; 
	
	$id = $_SESSION["id"]; 
	$account_activation_status = $_SESSION["account_activation_status"]; 
	$id_video_verification_status = $_SESSION["id_video_verification_status"]; 
	$id_video_verification_url = $_SESSION["id_video_verification_url"]; 
	$sponsor_username = $_SESSION["sponsor_username"]; 
	$recruits_number = $_SESSION["recruits_number"]; 
	$on_day_number_on_7_days_wish_list = $_SESSION["on_day_number_on_7_days_wish_list"]; 
	$primary_website_domain = $_SESSION["primary_website_domain"]; 
	$primary_website_email = $_SESSION["primary_website_email"]; 
	$username = $_SESSION["username"]; 
	$first_name = $_SESSION["first_name"]; 
	$middle_name = $_SESSION["middle_name"]; 
	$surname = $_SESSION["surname"]; 
	$gender = $_SESSION["gender"]; 
	$age_range = $_SESSION["age_range"]; 
	$religion = $_SESSION["religion"]; 
	$marital_status = $_SESSION["marital_status"]; 
	$working_status = $_SESSION["working_status"]; 
	$profession = $_SESSION["profession"]; 
	
	$recipient_username = $user;

	?> 
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"> 
	<html> 
	<head> 
  	<meta content="text/html; charset=ISO-8859-1"  http-equiv="content-type"> 
	<title><?php $user ?>Notices in <?php $server_time ?> time.</title>
	</head> 
	<body> 
	<br> 
	<center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> 
	<br> 
	<br> 
	
<?php 
	if (!$conn)
{
    $error = mysqli_connect_error();
    $errno = mysqli_connect_errno();
    print "$errno: $error\n";
    exit();
}

$recipient_username = $user;
$query = "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices WHERE recipient_username = ?";

if ($stmt = mysqli_prepare($conn, $query)) {

    /* bind param */
    mysqli_stmt_bind_param($stmt,'s',$recipient_username);
	
	/* execute statement */
    mysqli_stmt_execute($stmt);	

    /* bind result variables */
    $result = mysqli_stmt_bind_result($stmt,$id,$date_and_time,$recipient_username,$sender_username,$message);
	//$result = mysqli_stmt_store_result($stmt);
	//mysqli_free_result($result);
	
	$rows_num = mysqli_stmt_num_rows($stmt);
    
    ?> 
	<?php 
	if ($rows_num<1){
		echo "Rows yielded: 0<br>";
		echo "$user: $user<br>";
		echo "recipient_username: $recipient_username<br>";		
	}
	else
	{
		echo "number of rows yielded: $rows_num<br>";		
	}
	if (!$result){
		echo "Results yielded: 0<br>";
		echo "$user<br>";
		echo "recipient_username: $recipient_username<br>";	
		
	}
	else
	{
		//FOLLOWING ECHOES CHECK WHETHER $RESULTS GOT PULLED OR NOT
		echo 'Results yielded $id:'; echo "$id<br>"; //THIS IS GETTING YIELDED
		echo 'Results yielded $date_and_time:'; echo "$date_and_time<br>"; //WHY IS THIS FAILING TO GET YIELDED ?
		echo 'Results yielded $recipient_username:'; echo "$recipient_username<br>"; //THIS IS GETTING YIELDED
		echo 'Results yielded $sender_username:'; echo "$sender_username<br>"; //WHY IS THIS FAILING TO GET YIELDED ?
		echo 'Results yielded $message:'; echo "$message<br>"; //WHY IS THIS FAILING TO GET YIELDED ?
	}
	?>
	<table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"> 
	<?php if($rows_num) {?> 
	<tr name="headings"> 
	<td bgcolor="#FFFFFF" name="column-heading_submission-number">Submission Number</td> 
	<td bgcolor="#FFFFFF" name="column-heading_logging-server-date-&-time">Date & Time in <?php $server_time ?></td> 
	<td bgcolor="#FFFFFF" name="column-heading_username">To</td> 
	<td bgcolor="#FFFFFF" name="column-heading_gender">From</td> 
	<td bgcolor="#FFFFFF" name="column-heading_age-range">Notice</td> 
	</tr> 
	
    <?php while($row = mysqli_stmt_fetch($result)){ ?> 	
	<tr name="user-details"> 
	<td bgcolor="#FFFFFF" name="submission-number"><?php echo $row['id']; ?></td> 
	<td bgcolor="#FFFFFF" name="logging-server-date-&-time"><?php echo $row['date_and_time']; ?></td> 
	<td bgcolor="#FFFFFF" name="username"><?php echo $row['recipient_username']; ?></td> 
	<td bgcolor="#FFFFFF" name="gender"><?php echo $row['sender_username']; ?></td> 
	<td bgcolor="#FFFFFF" name="age-range"><?php echo $row['message']; ?></td> 
	</tr> 
    <?php } ?> 
    <tr name="pagination"> 
    <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
    <?php 
	
        if($rows_num <= $page_size) 
        { 
            echo "Page 1";  
		} 
        else 
        { 
            for($i=1;$i<=$page_count;$i++) 
            echo "<a href=\"{$_SERVER['PHP_SELF']}?page_number={$i}\">{$i}</a>  "; 
        } 	
        ?> 	
    </td> 
    </tr> 
    <?php } else { ?> 
    <tr> 
    <td bgcolor="FFFFFF">No record found! Try another time.</td> 
    </tr> 
    <?php }?> 
    </table> 
	<br> 
	<br> 
	<center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> 
	<br> 
	<br> 
</div> 
<br> 
</body> 
</html> 
<?php 

//close statement
mysqli_stmt_close($stmt);
}

//close connection
mysqli_close($conn);

}

?>
See attachment.
 

Attachments

Latest threads
Replies
0
Views
590
Replies
2
Views
789
Similar threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top