What's new

Closed Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\blogs\php-files\update.php on line 42

Status
Not open for further replies.

Captcha-Google

Forum Veteran
Elite
Joined
Apr 29, 2017
Posts
943
Reaction
634
Points
530
<?php


// Initialize the session
session_start();

// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}

// Check existence of id parameter before processing further
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
// Include config file
require_once "config.php";

// Prepare a select statement
$sql = "SELECT * FROM post WHERE id = ?";

if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);

// Set parameters
$param_id = trim($_GET["id"]);

// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);

if(mysqli_num_rows($result) == 1){
/* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);

// Retrieve individual field value
$post_content = $row["post_content"];
$location = $row["location"];
$created = $row["created"];
} else{
// URL doesn't contain valid id parameter. Redirect to error page
header("location: error.php");
exit();
}

} else{
echo "Oops! Something went wrong. Please try again later.";
}
}

// Close statement
mysqli_stmt_close($stmt);

// Close connection
mysqli_close($link);
} else{
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Record</title>
<link rel="stylesheet" href="You do not have permission to view the full content of this post. Log in or register now.">
<script src="ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
.MakaleYazariAdi{
line-height:34px;
}

#BegeniButonlari{
float:right;
margin-top:15px;
}
</style>
</head>
<body>



<link href="maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<br><br><br>

<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<a href="#" class="MakaleYazariAdi" style="text-decoration: none;"><?php echo htmlspecialchars($_SESSION["username"]); ?> post</a>
<div class="btn-group" style="float:right;">
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-cog"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<?php


echo" <ul class='dropdown-menu'>
<li><a href='update.php?id=". $row['id']."/title=". $row['post_title']."' title='Edit Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span> Edit</a></li>
<li role='separator' class='divider'></li>
<li><a href='delete.php?id=". $row['id'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span> Delete</a></li>
</ul>"
?>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="You do not have permission to view the full content of this post. Log in or register now." alt="Kurt">
</a>
</div>
<div class="media-body">
<h4 class="media-heading" title="<?php echo $row["post_title"]; ?>"><?php echo $row["post_title"]; ?></h4>
<?php echo $row["post_content"]; ?>
<br>
<div class="clearfix" title="<?php echo $row["location"]; ?>"><?php echo $row["location"]; ?></div>
<div class="clearfix" title="<?php echo $row["created"]; ?>"><?php echo $row["created"]; ?></div>
<div class="btn-group" role="group" id="BegeniButonlari">
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-thumbs-up"></span></button>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-thumbs-down"></span></button>
<button type="button" class="btn btn-default"><a href="welcome.php">Back<a/></button>
</div>
</div>
</div>
</div>
</div>
</div>


</body>
</html>
 
I'm not sure

if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);

// Set parameters
$param_id = trim($_GET["id"]);

di ba dapat nasa taas si param_id bago i bind?
 
actually tama ito sir.. kasi magiging undefined yung $param_id sa loob ng mysqli_stmt_bind_param($stmt, "i", $param_id); kaya magiging null yung id sa SELECT query which magiging result ng boolean false na return ng mysqli_fetch_array($result, MYSQLI_ASSOC);
 
Status
Not open for further replies.

Similar threads

Back
Top