I am new in mysqli. I was using mysql and converting it in mysqli. When the data in my database are empty the error showed up and said " Undefined variable: candidate_name_5" but in mysql when the data in mydatabase is empty it still works. I dont know whats the problem. Its working fine in mysql but many errors in mysqli. Please help me what is the problem
<?php
require('connection.php');
$connect = mysqli_connect('localhost','root','','smart_id_user');
// retrieving candidate(s) results based on position
if (isset($_POST['monthReport'])){
/*
$resulta = mysql_query("SELECT * FROM tbCandidates where candidate_name='Luis Nani'");
while($row1 = mysql_fetch_array($resulta))
{
$candidate_1=$row1['candidate_cvotes'];
}
*/
$monthReport = $_POST['monthReport'];
$results = mysqli_query($connect,"SELECT * FROM voting_tbCandidates where candidate_position='$monthReport'");
$row1 = mysqli_fetch_array($results); // for the first candidate
$row2 = mysqli_fetch_array($results); // for the second candidate
$row3 = mysqli_fetch_array($results);
$row4 = mysqli_fetch_array($results);
$row5 = mysqli_fetch_array($results);
$row6 = mysqli_fetch_array($results);
$row7 = mysqli_fetch_array($results);
$row8 = mysqli_fetch_array($results);
$row9 = mysqli_fetch_array($results);
$row10 = mysqli_fetch_array($results);
$row11 = mysqli_fetch_array($results);
$row12 = mysqli_fetch_array($results);
if ($row1){
$candidate_name_1=$row1['candidate_name']; // first candidate name
$candidate_1=$row1['candidate_cvotes']; // first candidate votes
}
if ($row2){
$candidate_name_2=$row2['candidate_name']; // second candidate name
$candidate_2=$row2['candidate_cvotes']; // second candidate votes
}
if ($row3){
$candidate_name_3=$row3['candidate_name'];
$candidate_3=$row3['candidates_cvotes'];
}
if($row4){
$candidate_name_4=$row4['candidate_name'];
$candidate_4=$row4['candidate_cvotes'];
}
if($row5){
$candidate_name_5=$row5['candidate_name'];
$candidate_5=$row5['candidate_cvotes'];
}
if($row6){
$candidate_name_6=$row6['candidate_name'];
$candidate_6=$row6['candidate_cvotes'];
}
if($row7){
$candidate_name_7=$row7['candidate_name'];
$candidate_7=$row7['candidate_cvotes'];
}
if($row8){
$candidate_name_8=$row8['candidate_name'];
$candidate_8=$row8['candidate_cvotes'];
}
if($row9){
$candidate_name_9=$row9['candidate_name'];
$candidate_9=$row9['candidate_cvotes'];
}
}
else
// do nothing
?>
<?php
// retrieving positions sql query
$positions=mysqli_query($connect,"SELECT * FROM voting_tbPositions")
or die("There are no records to display\n" . mysqli_error());
?>
<?php
session_start();
//If your session isn't valid, it returns you to the login screen for
protection//
if(empty($_SESSION['user_id'])){
}
?>
<?php if(isset($_POST['monthReport']))
{$totalvotes=$candidate_1+$candidate_2+$candidate_3+$candidate_4;} ?>
<html><head>
<div id="mySidenav" class="sidenav">
×
HOME
<a><hr></a>
VOTE
<a><hr></a>
POLL RESULTS
<a><hr></a>
LOGOUT
</div>
<div id="main">
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰
</span>
<script language="JavaScript" src="js/admin.js">
</script>
</head><body bgcolor="tan">
<center>
<font color = "white" size="7"> <div id="hihi">ONLINE VOTING SYSTEM</div></font>
<br><br>
<br>
<br></center>
<div id="page">
<div id="header">
<h1>POLL RESULTS </h1>
</div>
<div id="container">
<table width="420" align="center">
<form method="POST" action="refresh.php">
<tr>
<td>Choose Position</td>
<td><SELECT name="monthReport" id="monthReport" onchange="form.submit()">
<OPTION VALUE="select">select
< ?php
//loop through all table rows
while ($row=mysqli_fetch_array($positions)){
echo "<OPTION VALUE=$row[position_name]>$row[position_name]";
}
?>
</SELECT></td>
<script type="text/javascript">
document.getElementById('month').value = "<?php echo $_POST['monthReport'];?>";
</script>
<?php
echo '<div id="gitna">';
echo $monthReport;
echo '</div>';
?>
<?php if(isset($_POST['monthReport'])){echo $candidate_name_1;} ?>:<br>
<img src="images/candidate-1.gif"
width='<?php if(isset($_POST['monthReport'])){ if ($candidate_2 ||
$candidate_1 || $candidate_3 || $candidate_4 || $candidate_5!= 0){echo(100*round($candidate_1/($candidate_2+$candidate_1+$candidate_3+$candidate_4+$candidate_5),5));}} ?>'
height='20'>
<?php if(isset($_POST['monthReport'])){ if ($candidate_2 ||
$candidate_1 || $candidate_3 ||$candidate_4 || $candidate_5!= 0)
{echo(100*round($candidate_1/($candidate_2+$candidate_1+$candidate_3+$candidate_4+$candidate_5),5));}} ?>% of <?php if(isset($_POST['monthReport'])){echo $totalvotes;} ?> total votes
<br> votes <?php if(isset($_POST['monthReport'])){ echo $candidate_1;} ?>
<br>
<br>
<?php if(isset($_POST['monthReport'])){ echo $candidate_name_2;} ?>:<br>
<img src="images/candidate-2.gif"
width='<?php if(isset($_POST['monthReport'])){ if ($candidate_2 || $candidate_1 || $candidate_3 || $candidate_4 || $candidate_5!= 0){echo(100*round($candidate_2/($candidate_2+$candidate_1+$candidate_3+$candidate_4+$candidate_5),5));}} ?>'
height='20'>
<?php if(isset($_POST['monthReport'])){if ($candidate_5 || $candidate_4 || $candidate_3 || $candidate_2 || $candidate_1!=0){echo(100*round($candidate_5/($candidate_5+$candidate_4+$candidate_3+$candidate_2+$candidate_1),5));}} ?>% of <?php if(isset($_POST['monthReport'])){echo $totalvotes;} ?> total votes
<br>votes <?php if(isset($_POST['monthReport'])){echo $candidate_5;} ?>
<br>
<br>
<br>
</div>
</body></html>
i just add
error_reporting(1);
and everything works fine now
Related
I have search webpage, but when the search is run, there is a blank first result.
<?php include "headnav.php";
$count = 0;
$sql = "SELECT * FROM lost_property";
if (!empty($_POST)) {
$name = mysqli_real_escape_string($dbconnect, htmlspecialchars($_POST['name']));
$item = mysqli_real_escape_string($dbconnect, htmlspecialchars($_POST['item']));
$area = mysqli_real_escape_string($dbconnect, htmlspecialchars($_POST['area']));
$sql = "
SELECT *
FROM lost_property
JOIN item
ON lost_property.itemID = item.itemID
JOIN area
ON lost_property.areaID = area.areaID
WHERE name LIKE '%$name%'
AND item LIKE '%$item%'
AND area LIKE '%$area%'
ORDER
BY lost_property.name ASC
";
$search_query = mysqli_query($dbconnect, $sql);
$count = mysqli_num_rows($search_query);
}
$result = $dbconnect->query($sql);
?>
<body>
<div class="form">
<h1>Search for lost property here:</h1>
<form action="" method="POST">
Name:
<input type="text" placeholder="Name" name="name">
Item type:
<select name="item" class="dropdown">
<option value="" disabled selected>Item</option>
<?php
$item_sql = "SELECT DISTINCT item FROM `lost_property`
JOIN item ON (lost_property.itemID = item.itemID)
ORDER BY item ASC
";
$item_query = mysqli_query($dbconnect, $item_sql);
$item_rs = mysqli_fetch_assoc($item_query);
do {
?>
<option value="<?php echo $item_rs['item']; ?>"><?php echo $item_rs['item']; ?></option>
<?php
} while ($item_rs = mysqli_fetch_assoc($item_query));
?>
</select>
Area (where it was found):
<select name="area" class="dropdown">
<option value="" disabled selected>Area</option>
<?php
$area_sql = "SELECT DISTINCT area FROM `lost_property`
JOIN area ON (lost_property.areaID = area.areaID)
ORDER BY area ASC
";
$area_query = mysqli_query($dbconnect, $area_sql);
$area_rs = mysqli_fetch_assoc($area_query);
do {
?>
<option value="<?php echo $area_rs['area']; ?>"><?php echo $area_rs['area']; ?></option>
<?php
} while ($area_rs = mysqli_fetch_assoc($area_query));
?>
</select>
<input type="submit" value="Search" name="btn">
</form>
</div>
<div class="gallery">
<h2>Search results:</h2>
<?php
//check for results. If there are none display error
if ($count < 1) {
?>
<div class="error">
<h1>No results were found.</h1>
</div>
<?php
} //end if
else {
do {
?>
<!-- display image and information from database and show in gallery -->
<div class="results">
<h3><?php echo $search_rs['name']; ?></h3>
<h3><?php echo $search_rs['item']; ?></h3>
<p><?php echo $search_rs['area']; ?></p>
</div>
<?php
} // end of do
while ($search_rs = mysqli_fetch_assoc($search_query));
} //end else
//if there are any display
?>
</div>
</table>
</body>
</html>
It's hard to see without any CSS, but no matter what is searched, there is always one result, but the h3 and p fields don't have any content. If there wasn't the no results error message it would pop up there too. What is causing this first result?
Use while (){}, if you use do instead it will run once first (credit to Magnus Eriksson).
It ends up like
else {
while ($search_rs = mysqli_fetch_assoc($search_query)) {
?>
<!-- display image and information from database and show in gallery -->
<div class="results">
<h3><?php echo $search_rs['name']; ?></h3>
<h3><?php echo $search_rs['item']; ?></h3>
<p><?php echo $search_rs['area']; ?></p>
</div>
<?php
} // end of do
} //end else
//if there are any display
?>
instead of
else {
do {
?>
<!-- display image and information from database and show in gallery -->
<div class="results">
<h3><?php echo $search_rs['name']; ?></h3>
<h3><?php echo $search_rs['item']; ?></h3>
<p><?php echo $search_rs['area']; ?></p>
</div>
<?php
} // end of do
while ($search_rs = mysqli_fetch_assoc($search_query));
} //end else
//if there are any display
?>
Hey friends I want to refresh my database after checking the access token is working or not I want to delete the Facebook expire access token without deleting the working access token but my this script delete my all user access token and I don't know why I am new in PHP
<body>
<div id="wrap" class="boxed">
<center>
<br><br>
<div class="bannerX" style="width: 600px;">
<div class="logo">
<section class="logo">
<img src="logo-new.png">
</section>
</div>
<br>
<hr>
<br>
<?php
include'config.php';
$items = mysql_query("SELECT * FROM token_all");
$thispage = $PHP_SELF;
$num = mysql_num_rows($items);
$per_page = 300;
$start = #$_GET['start'];
if(empty($start)) $start = 000;
?>
<?php
// Turn off all error reporting
error_reporting(0);
?>
<center>
<?php
$i = "0";
if($start+$per_page<$num){
?>
[Next Like]
<?php
}
$result = mysql_query("SELECT * FROM token_all LIMIT $start,$per_page");
if($result){
while($row = mysql_fetch_array($result))
{
$token = $row[token];
$userData = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token.'&fields=name,id'),true);print($userData[name]).'<br/>';
if(!$userData[name]){
$i++;
mysql_query("
DELETE FROM
token_all
WHERE
token='" . mysql_real_escape_string($token) . "'
");
}
}
}
echo $i;
?>
</body>
</html>
Thanks in advance
I am trying to repeat a div the same div multiple times with as many rows as i have in the database table. a non working example i made of what i want is below.
<?php for ($i=0; $i < 3; $i++) {
?><!-- switch the three with the number of rows in the table-->
I would want to loop the container and switch the database query with the value of i.
<div id = "bodyContainer">
<form class="review">
<div class="reviewContainer">
<div class = "images">
<?php
$link = mysqli_connect("localhost", "root", "root","DJP");
if (mysqli_connect_error()) {
die("Could not connect to database");
}
$query = "SELECT * FROM reviews WHERE id = '<?php echo $i ?><!--switch the value of i here-->'";
$result=mysqli_query($link, $query);
$row = mysqli_fetch_array($result);
echo '<img height = 90% width = 100% src="data:image/jpeg;base64,'.$row[3].' " />';
?>
</div>
<!--<div class="title">
<?php
//echo $row[1];
?>
</div>-->
<div class = "comment">
<?php
echo $row[2];
?>
</div>
<div class = "rating" style = "float: right;">
<?php
echo $row[4];
?>
<br/>
<br/>
stars
</div>
</div><!--end review-->
</form>
</div><!--end body container-->
<?php;}?><!-- end the for loop so all the divs can be re-done with a new entry for the query. I would move the $link out of loop also.-->
Just fetch all the rows once and then go through them as you print the data:
$link = mysqli_connect("localhost", "root", "root","DJP");
if (mysqli_connect_error()) {
die("Could not connect to database");
}
$query = "SELECT * FROM reviews";
$result=mysqli_query($link, $query);
while($row = mysqli_fetch_array($result)){ ?>
<div id = "bodyContainer">
<form class="review">
<div class="reviewContainer">
<div class = "images">
<?php
echo '<img height = 90% width = 100% src="data:image/jpeg;base64,'.$row[3].' " />';
?>
</div>
<!--<div class="title">
<?php
//echo $row[1];
?>
</div>-->
<div class = "comment">
<?php
echo $row[2];
?>
</div>
<div class = "rating" style = "float: right;">
<?php
echo $row[4];
?>
<br/>
<br/>
stars
</div>
</div><!--end review-->
</form>
</div><!--end body container-->
<?php } ?>
I am making a forum system to strengthen my php and make a website for a community that i have. I do not know how to check if the sub category i have selected is inside the specified category for example we have localhost/forum/sub_category.php?cat=1&sub_cat=1 what i want to know is to figure out if a user tries to set the category id to 3 and the sub_category to 4 and the sub_category id does not exist. How do i use $_GET to check for that, then show the user a message saying that the specified sub category does not exist. Here's My Code:
<?php
include '../inc/dbc.php';
include '../inc/functions.php'
?>
<?php
if(isset($_GET['user']) && !empty($_GET['user'])) {
$username = $_GET['user'];
} else {
$username = $_SESSION['username'];
}
$my_name = $_SESSION['username'];
$firstname = getuser($username, 'firstname');
$lastname = getuser($username, 'lastname');
?>
<!DOCTYPE html>
<html>
<head>
<title>EWC Forums</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<?php include 'header.php';?>
<div class='main'>
<div class='body'>
<div class='left'>
<?php
if (isset($_GET['cat']) && isset($_GET['sub_cat'])) {
$cat_query = mysqli_query($mysqli, "SELECT * FROM categories Where");// this is not done yet
} else if ($_GET['sub_cat'] == 0) {
$msg = 'That Sub Category Was Not Found In Our Database';
} else {
?>
<div class='message'><?php echo $msg;?></div>
<?php
}
?>
</div>
<div class='right'>
</div>
<div class='clear'></div>
</div>
</div>
</body>
</html>
This is the main page that shows the categories and the sub_categories:
<?php
include '../inc/dbc.php';
include '../inc/functions.php'
?>
<?php
if(isset($_GET['user']) && !empty($_GET['user'])) {
$username = $_GET['user'];
} else {
$username = $_SESSION['username'];
}
$my_name = $_SESSION['username'];
$firstname = getuser($username, 'firstname');
$lastname = getuser($username, 'lastname');
?>
<!DOCTYPE html>
<html>
<head>
<title>EWC Forums</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<?php include 'header.php';?>
<div class='main'>
<div class='body'>
<?php
if(loggedIn() == false) {
?>
<div class='mbli'>You Are Not Logged In Right Now. Click Here To Login</div><br>
<?php
}
?>
<div class='forum'>
<div class='tools'>
<?php
$sql = mysqli_query($mysqli, "SELECT * FROM users WHERE rank = 'Administrator' ");
$res = mysqli_num_rows($sql);
if ($sql == 1) {
?>
<div class='forummenu'>
<i class=''></i> New Category
<i class=''></i> New Sub Category
</div>
<?php
}
?>
</div>
<?php
$check_forum = mysqli_query($mysqli, "SELECT * FROM categories");
while ($run = mysqli_fetch_array($check_forum)) {
$cat_id = $run['cat_id'];
$creator = $run['creator'];
$cat_name = $run['name'];
$create_date = $run['create_date'];
$activated = $run['activated'];
?>
<div class='cat'>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;border-style:solid;border-width:1px;overflow:hidden;}
.tg .tg-7ht0{background-color:#f07075;color:#ffffff}
</style>
<table>
<tr class="cat_head">
<th class="tg-7ht0"><b><?php echo $cat_name;?></b><i><?php echo $create_date;?></i></th>
<th class="tg-7ht0">Threads</th>
<th class="tg-7ht0">Posts</th>
<th class="tg-7ht0">Latest Posts</th>
</tr>
<?php
$check_subcat = mysqli_query($mysqli, "SELECT * FROM subcategories WHERE cat_id= '$cat_id' ");
while ($run_sub = mysqli_fetch_array($check_subcat)) {
$sub_cat_id = $run_sub['sub_cat_id'];
$creator_subcat = $run_sub['creator'];
$name_sub = $run_sub['name'];
$sub_desc = $run_sub['sub_desc'];
$create_date_sub = $run_sub['create_date'];
?>
<tr class='sub_cat'>
<td class="tg-7ht0"><div class='sub_img'><img src="http://minotar.net/helm/<?php echo $creator_subcat;?>/32"></div><div class='sub_body'><a href='sub_category.php?cat=<?php echo $cat_id;?>&sub_cat=<?php echo $name_sub;?>'><div class='sub_tit'><b><?php echo $name_sub; ?></b><div class='desc'><?php echo $sub_desc;?></div></div></a><i class='date'><?php echo $create_date_sub; ?></i></div></td>
<td class="tg-7ht0">0</td>
<td class="tg-7ht0">0</td>
<td class="tg-7ht0">Nub picture</td>
</tr>
<?php
}
?>
<div class='clear'></div>
</table>
</div>
<?php
}
?>
</div>
</div>
</div>
</body>
</html>
Also if there's another way to do this please suggest it, but i do prefer this one. And if you need more code just ask.
Try use this :
EDIT: with the sub categories screenshot on comments :
<?php
if (isset($_GET['cat']) && isset($_GET['sub_cat'])) {
$cat_query = mysqli_query($mysqli, "SELECT * FROM SubCategoryTableName WHERE sub_cat_id='".$_GET['sub_cat']."' AND cat_id ='".$_GET['cat']."'");// this is not done yet
// Check if number of ROWS are zero/sub category notfound! .
if(mysqli_num_rows($cat_query)) == 0)
{
// show error and die
die('The requested sub/category not found.');
}
} else if ($_GET['sub_cat'] == 0) {
$msg = 'That Sub Category Was Not Found In Our Database';
} else {
?>
Please note this code are work , but always must secure the inputs that requested from users.
I don't know if your id's will go further up automatically otherwise you just put a check statement to see if the cat and sub cat are the correct number and not too high or low.
If you do depend on your database then you could ask a query to see if it exists or not or ask it to give the latest id in the database and use this then to check if your id is lower than that.
I hope that I understood your question correctly here. Don't forget to validate your GET request btw ;)
Thanks for all the help, because of you guys i figured how to fix the problem, it may not be the correct way but it's close. Here's my code:
<?php
include '../inc/dbc.php';
include '../inc/functions.php'
?>
<?php
if(isset($_GET['user']) && !empty($_GET['user'])) {
$username = $_GET['user'];
} else {
$username = $_SESSION['username'];
}
$my_name = $_SESSION['username'];
$firstname = getuser($username, 'firstname');
$lastname = getuser($username, 'lastname');
?>
<!DOCTYPE html>
<html>
<head>
<title>EWC Forums</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<?php include 'header.php';?>
<div class='main'>
<div class='body'>
<?php
if(isset($_GET['cat']) && isset($_GET['sub_cat'])) {
$sub = $_GET['sub_cat'];
$cat = $_GET['cat'];
$sql = mysqli_query($mysqli, "SELECT * FROM subcategories WHERE sub_cat_id = '$sub' AND cat_id = '$cat' ");
if (!$sql) {
$msg = 'Sorry We Kept Looking, But We Found Nothing ;-;';
} else {
if (mysqli_num_rows($sql) == 0) {
$msg = 'Ask An Admin';
} else {
?>
<?php
while ($row = mysqli_fetch_array($sql)) {
?>
<div class='cat'>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;border-style:solid;border-width:1px;overflow:hidden;}
.tg .tg-7ht0{background-color:#f07075;color:#ffffff}
</style>
<table>
<tr class="cat_head">
<th class="tg-7ht0"><b><?php echo $row['name'];?></b><i><?php echo $row['create_date'];?></i></th>
<th class="tg-7ht0">Views</th>
<th class="tg-7ht0">Replies</th>
<th class="tg-7ht0">Latest Posts</th>
</tr>
<?php
$thread_query = mysqli_query($mysqli, "SELECT * FROM threads WHERE sub_cat_id = $sub ");
while ($run = mysqli_fetch_array($thread_query)) {
$thread_id = $run['thread'];
$thread_author = $run['creator'];
$thread_title = $run['name'];
$thread_date = $run['create_date'];
?>
<tr class='sub_cat'>
<td class="tg-7ht0"><div class='sub_img'><img src="http://minotar.net/helm/<?php echo $thread_author; ?>/32"></div><div class='sub_body'><a href=''><b><?php echo $thread_title; ?></b></a > created by <a href='profile.php?user=<?php echo $thread_author;?>'><?php echo $thread_author;?></a> at <?php echo $thread_date; ?></div></td>
<td class="tg-7ht0">0</td>
<td class="tg-7ht0">0</td>
<td class="tg-7ht0">Nub picture</td>
</tr>
<?php
}
}
?>
<div class='clear'></div>
</table>
</div>
<?php
}
}
} else {
?>
<div class='message'><?php echo $msg; ?></div>
<?php
}
?>
<div class='clear'></div>
</div>
</div>
</body>
</html>
I am new to PHP and trying to display data from the database.
However it only displays data from one row but I want to show the data from multiple rows where the condition match. Here is my code I am using:
<?PHP
session_start();
if (!(isset($_SESSION['username']) && $_SESSION['username'] != '')) {
header ("Location: checklogin.php");
}
$con = mysqli_connect("localhost", "root", "", "map_my_way");
$fetch_row = $_SESSION['username'];
$result = mysqli_query($con,"SELECT * FROM members where username='$fetch_row'");
while($row = mysqli_fetch_array($result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$email = $row['email'];
$m_no = $row['m_no'];
$v_name = $row['v_name'];
$capacity = $row['capacity'];
$fuel_type = $row['fuel_type'];
}
$result2 = mysqli_query($con,"SELECT s_a_name FROM locations where username='$fetch_row'");
$row2 = mysqli_fetch_array($result2);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Profile Page</title>
<link rel="stylesheet" type="text/css" href="profile.css">
</head>
<body id="body">
<div id="mmw"> <span> MAP MY WAY </span></div>
<div id="title_box">
<button id="lvbutton">My Profile</button>
<button id="lvbutton">Maps</button>
<button id="lvbutton">Edit Profile</button>
<button id="lvbutton" style="float:right; margin- right:10px;">Sign-Out</button>
</div>
<div id="box">
<div id="name_box"><span>Welcome <?php echo($_SESSION['username']); ?></span></div>
<div id="box1">
<div> <p id="link">Your Information </p>
<ul style="margin-top:20px; padding-left:0;">
<li><span>First Name : <?php echo $first_name; ?></span></li><br>
<li><span>Last Name : <?php echo $last_name; ?></span></li><br>
<li><span>Email : <?php echo $email; ?></span></li><br>
<li><span>Age : <?php echo $m_no; ?></span></li><br>
<li><span>Current Vehical : <?php echo $v_name; ?></span></li><br>
<li><span>Fuel Type: <?php echo $fuel_type; ?> </span></li><br>
<li><span>Seating Capacity : <?php echo $capacity; ?></span></li><br>
</ul>
</div>
</div>
<div id="box2"> <p id="link">Saved Routes </p>
<ul style="margin-top:20px;">
<span> <?php foreach($row2 as $data)
{echo "route Name : $data <br>" ; };
?>
</span>
</ul>
</div>
</div>
</div>
</body>
</html>
Your query on the members table is only going to return one row, so you don't really need to have $row = mysqli_fetch_array($result) in a loop (that shouldn't break your script, though). Your query on the locations table will potentially return more than one row, so you do need to loop on that one. Something like:
$result2 = mysqli_query($con,"SELECT s_a_name FROM locations where username='$fetch_row'");
$savedRoutes = "";
while($row2 = mysqli_fetch_array($result2))
{
$savedRoutes .= "route Name : " . $row2['s_a_name'] . "<br/>";
}
will put all the data together in a string ($savedRoutes) that can be echoed down in the "Saved Routes" section of your html code.
Alternatively, you can put the loop down in the "Saved Routes" section and just echo out each line as you loop through. Personally I think putting the loop in the top and concatenating the data into a string is a bit cleaner and easier to read.