I have a problem with the Hostgator DB server. first thing first, I am a new baby on this. So, DB connects and I can log in but it doesn't allow me to save new user details and to pull out any info from DB. Everything works perfectly on localhost. So I realise that it's because of HostGator DB or $_SESSION. The code -
include 'connection.php';
session_start();
$id=$_SESSION['id'];
$query=mysqli_query($db,"SELECT * FROM users where user_id='$id'")or die(mysqli_error());
$row=mysqli_fetch_array($query);
And if I manually change $id to The No of user-id example-(1) everything works perfectly so I can save it and any changes appear on DB same as on a webpage. So seems it is not recognising Session id for the user who changes his user information.
The code -
include 'connection.php';
session_start();
$id=$_SESSION['id'];
$query=mysqli_query($db,"SELECT * FROM users where user_id='1'")or die(mysqli_error());
$row=mysqli_fetch_array($query);
Does anyone know what is the issue??? I don't care about security issues on the code. Just need to be able to run the PHP code on the HostGator host and DB.
The full code after I edited regarding suggestions -
<?php
session_start();
include('connection.php');
$id=$_SESSION['id'];
$query=mysqli_query($db,"SELECT * FROM users where user_id=$id");
$row=mysqli_fetch_array($query);
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>IT SourceCode</title>
<link rel="stylesheet" href="libs/css/bootstrap.min.css">
<link rel="stylesheet" href="libs/style.css">
<link rel="stylesheet" href="main.css">
<style>
img {
border-radius: 50%;
}
</style>
</head>
<h1>Profile</h1>
<div class="profile-input-field">
<form method="post" action="#" >
<div class="form-group">
<td> <img src="<?php echo 'images/' . $row['profile_image'] ?>" width="100%" height="100%" alt="" class="button" value="<?php echo $row['profile_image']; ?>"> </td>
</div>
<div class="button" value="<?php echo $row['full_name']; ?>">
<h1><?php echo $row['full_name']; ?></h1>
</div>
<div class="form-group">
<a href="https://www.facebook.com/<?php echo $row['facebook']; ?>" type="button" class="btn btn-primary button" name="facebook" value="<?php echo $row['facebook']; ?>" style="width:20em;">Facebook Page</a>
</div>
<div class="form-group">
<a href="https://www.facebook.com/<?php echo $row['email']; ?>" type="button" class="btn btn-primary button" name="email1" value="<?php echo $row['email']; ?>" style="width:20em;">Send Email</a>
</div>
<center>
<a href="form.php">Edit Profile</a>
</center>
<center>
<a href="logout.php">Log out</a>
</center>
</form>
</div>
</html>
Got in Error log - PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given on line 6