hello I'm newbie in php field I need your help I'm going to try to fetch the data from database and display on my html page but when I'm going to run my project it's give me error like this
Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\uploadimg\userside\accountsetting.php:41 Stack trace: #0 C:\xampp\htdocs\uploadimg\userside\accountsetting.php(41): mysqli_fetch_assoc(false) #1 {main} thrown in C:\xampp\htdocs\uploadimg\userside\accountsetting.php on line 41
and my php code is as following
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "acktaimgupload";
$conn = mysqli_connect($host,$user,$pass, $db);
if(!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
?>
<?php
$sql = "select * from users where username = $username";
$rs = mysqli_query($conn, $sql);
//get row
$fetchRow = mysqli_fetch_assoc($rs);
?>
and my html form is as following
<form class="form" novalidate="">
<div class="row">
<div class="col">
<div class="row">
<div class="col">
<div class="form-group">
<label>Full Name</label>
<input class="form-control" type="text" name="username" placeholder="John Smith" value="<?
php echo $fetchRow['post_username']?>">
</div>
</div>
<div class="col">
<div class="form-group">
<label>Username</label>
<input class="form-control" type="text" name="username" placeholder="johnny.s"
value="johnny.s" >
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<label>Email</label>
<input class="form-control" type="email" name="email" placeholder="user@example.com" value="
<?php echo $fetchRow['post_email']?>">
</div>
</div>
</div>
</div>
</div>
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\uploadimg\userside\accountsetting.php on line 214
** – Apr 29 '21 at 06:38