$query = "SELECT * from approvedelectricity where id` = '$id';";
Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[
^]
SQL Injection[
^]
SQL Injection Attacks by Example[
^]
PHP: SQL Injection - Manual[
^]
SQL Injection Prevention Cheat Sheet - OWASP[
^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[
^]
-----
Advice: Learn to indent properly your code, it highlight its structure and it helps reading and understanding. It also helps spotting structures mistakes.
<?php
session_start();
include("connectdb.php");
if( isset( $_POST['id'])) {
$id = $_POST['id'];
}
$query = "SELECT * from approvedelectricity where id` = '$id';";
$result= mysqli_query($conn, $query);
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_array($result))
$rows[] = $row;
foreach($rows as $i){
if($i['message']=='approved'){
echo " liked your post";
}else{
echo "rejected";
}
}
}
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
mysqli_close($conn);
?><br/><a href="index.php">BACK</a>
Indentation style - Wikipedia[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]