Getting database fetched with select box - php

I'm testing my skills in php using bootstrap libraries and i'm in a dead end.
I have two tables, students and countries.
I got a select box where I get the country (and the ID associated) and I want to see the students from that country in a form.
Actually, I got the form, got the select but i can't find how to interact together.
Please, help me. Thanks
the code of my php
<?php
//Access to BDD
include 'database.php';
?>
<html>
<Head>
<title>List of students</title>
<script src="bootstrap/js/bootstrap.js"></script>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
</Head>
<body>
<!-- formulaire de recherche -->
<form class="panel-group form-horizontal" method="get" action="home.php" role="form">
<div class="panel panel-default">
<div class="panel-body">
<div class="panel-header">
<h4>Search</h4>
</div>
<div class="col-sm-3">
<!-- dropdown countries -->
<select class="form-control" id="select" name="country">
<option value="">country</option>
<?php
$sel_country = "SELECT * FROM countries";
$run_country = mysqli_query($conn,$sel_country);
while ($rows= mysqli_fetch_assoc($run_country)){
echo '<option value='.$rows['id'].'>'.$rows['brand_name'].'</option>';
}
?>
</select>
<br/>
<br/>
<button type="submit" class="btn btn-default" id="searchbtn" name="submit">Go</button>
</div>
</div>
</div>
</form>
<?php
//SQL listing all the students.
$sql = "SELECT * FROM student ORDER by student_id"; //CHOIX NON PLUS!!!
$run_sql = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_assoc($run_sql)){
echo '<div class="container">
<table class="table table-hover">
<tr>
<td><h2><a class="btn btn-info" href="detail.php?vo_id='.$rows['student_id'].'">'.$rows ['name'].'</a></h2></td>
</tr>
<tr>
<td>'.$rows ['surname'].'</td>
</tr>
<tr>
<td>'.$rows ['age'].'</td>
</tr>
<tr>
<td>'.$rows ['country'].'</td>
</tr>
</table>
</div>
<br>';
}?>

Update below code in existing:
Assuming that all code is on same page (home.php)
if(isset($_GET[country]))
{
$sql = "SELECT * FROM student WHERE country_id =". $_GET["country"]." ORDER by student_id"; //CHOIX NON PLUS!!!
$run_sql = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_assoc($run_sql)){
echo '<div class="container">
<table class="table table-hover">
<tr>
<td><h2><a class="btn btn-info" href="detail.php?vo_id='.$rows['student_id'].'">'.$rows ['name'].'</a></h2></td>
</tr>
<tr>
<td>'.$rows ['surname'].'</td>
</tr>
<tr>
<td>'.$rows ['age'].'</td>
</tr>
<tr>
<td>'.$rows ['country'].'</td>
</tr>
</table>
</div>
<br>';
}

Related

Send Form Value to Modal

I have a form that asks for 3 fields. Once the form is submitted, it should open a modal. In the modal a budget summary should show. The budget summary data is pulled from a database and the values are based on the 3 form fields entered. I can't seem to get the values to show up in the modal so the query will work but, the modal does open.
Here is the modal code:
<!-- Large modal -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" id="myLargeModalLabel" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content p-4">
<h4 class="modal-title">Budget Summary</h4>For Account: <?php echo $account; ?>, Fund: <?php echo $_POST['fund2']; ?>, DeptID#: <?php echo $deptID; ?><br><em>The budgeted balance is an estimate.</em></h4>
<br> <?php if ($budget_summary->TotalRows == 0) { // Show if mysqli recordset empty ?>There is no data. Please try your search again.<?php } ?>
<?php if ($budget_summary->TotalRows > 0) { // Show if mysqli recordset empty ?><table width="100%" class="table table-responsive" border="0" cellspacing="2" cellpadding="6" class="display" id="example2">
<thead>
<tr>
<th align="left" valign="top">Budgeted Amount</th>
<th align="left" valign="top">Budgeted Balance</th>
<th align="left" valign="top">Program</th>
</tr>
</thead>
<tbody>
<?php
while(!$budget_summary->atEnd()) {
?><tr>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_amount")); ?></td>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_balance")); ?></td>
<td valign="top"><?php echo($budget_summary->getColumnVal("program")); ?></td>
</tr>
<?php
$budget_summary->moveNext();
}
$budget_summary->moveFirst(); //return RS to first record
?>
</tbody>
</table><?php } ?>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Here is the sql query:
<?php
$budget_summary = new WA_MySQLi_RS("budget_summary",$sa,0);
$budget_summary->setQuery("SELECT * from budget_summary where fund = ? and account = ? and deptID = ?");
$budget_summary->bindParam("i", "".$_POST['fund '] ."", "-1"); //colname
$budget_summary->bindParam("i", "".$_POST['account'] ."", "-1"); //colname2
$budget_summary->bindParam("i", "".$_POST['funding_department'] ."", "-1"); //colname3
$budget_summary->execute();
?>
Here is the form:
<form method="POST" id="frm" name="frm">
<div class="row">
<div class="col mb-2">
<label for="account">Account:</label>
<select class="form-control" name="account2" id="account2" required>
<option></option>
<?php
while(!$accounts->atEnd()) { //dyn select
?>
<option value="<?php echo($accounts->getColumnVal("account")); ?>"><?php echo($accounts->getColumnVal("account")); ?>: <?php echo($accounts->getColumnVal("description")); ?></option>
<?php
$accounts->moveNext();
} //dyn select
$accounts->moveFirst();
?>
</select>
</div>
<div class="col mb-2">
<label for="fund">Fund:</label>
<select class="form-control" name="fund2" id="fund2" required>
<option></option>
<?php
while(!$funds->atEnd()) { //dyn select
?>
<option value="<?php echo($funds->getColumnVal("fundID")); ?>"><?php echo($funds->getColumnVal("fundID")); ?>: <?php echo($funds->getColumnVal("fund")); ?></option>
<?php
$funds->moveNext();
} //dyn select
$funds->moveFirst();
?>
</select>
</div>
</div>
<div class="row">
<div class="col mb-2">
<label for="fund">Department ID#:</label>
<input type="text" name="funding_department2" id="funding_department2" class="form-control input-md" autocomplete="off" value="" required>
</div></div>
<button type="submit" name="submit2" id="submit2" class="btn-lg btn-info">Search</button>
</form>
<script>
$(document).ready(function() {
$('#frm').on('submit', function(e){
$('#myLargeModalLabel').modal('show');
e.preventDefault();
});
});
</script>
Any tips would be appreciated on how to make this happen. I have been trying for days to figure it out. Thank you.
Do you insert the data directly into the databse or into fields in your modal?
Try the following:
Insert Data into the fields (if you have them), than try to print them with either PHP or Java to see if you recieve any values.
If you recieve them with java and can print them with java:
Your client gets the data that you insert but PHP is the serverside of you programm. You need to get the data with a php-statement.

Filter database table through drop-down list

I need to filter the table depends on the selected values of the drop-down lists. So know I need to know how to return the filter result into the page. I made the filter result in search.php but I can't return the filter result to the table again. The filter should filter by user ID or product ID for now.
<body>
<?php include('navbar.php'); ?>
<!-- Page header -->
<div class="container">
<h1 class="page-header text-center">Order system</h1>
</div>
<!-- Search -->
<div class="container">
<h3 class="text-left">Search</h3>
<div class="col-md-4">
<form method="post" action="search.php">
<div class="form-group">
<select name="search_date" class="form-control">
<option value="">Date</option>
<option value="">All time</option>
<option value="">Last 7 days</option>
<option value="">Today</option>
</select>
</div>
<div class="form-group">
<select name="user_id" class="form-control">
<option value="">User</option>
<option value="1">John Smith</option>
<option value="2">Laura Stone</option>
<option value="3">Jon Olseen</option>
</select>
</div>
<div class="form-group">
<select name="product_id" class="form-control">
<option value="">Product</option>
<option value="1">Pepsi Cola</option>
<option value="2">Coca Cola</option>
<option value="3">Fanta</option>
</select>
</div>
<div>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> Filter</button>
</div>
</form>
</div>
</div>
<!-- Order History -->
<div class="container">
<h3 class="text-left">Order History</h3>
<table class="table table-striped table-bordered">
<thead>
<th>User</th>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Date</th>
<th>Actions</th>
</thead>
<tbody>
<?php
$sql="SELECT * FROM orders o JOIN user u ON o.user_id=u.user_id JOIN product p ON o.product_id=p.product_id";
$query=$conn->query($sql);
while($row=$query->fetch_array()){
?>
<tr>
<td><?php echo $row['user_name']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['product_price']; ?></td>
<td><?php echo $row['order_quantity']; ?></td>
<td><?php echo $row['order_price']; ?></td>
<td><?php echo $row['order_date']; ?></td>
<td>
<span class="glyphicon glyphicon-pencil"></span> Edit || <span class="glyphicon glyphicon-trash"></span> Delete
<?php include('order_modal.php'); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
</html>
<?php
include('conn.php');
$search_date=$_POST['search_date'];
$user_id=$_POST['user_id'];
$product_id=$_POST['product_id'];
$sql="select * from orders where user_id='$user_id' OR product_id='$product_id'";
$query=$conn->query($sql);
$row=$query->fetch_array();
header('location:orderhistory.php');
?>
<?php include('header.php'); ?>
<body>
<?php include('navbar.php'); ?>
<!-- Page header -->
<div class="container">
<h1 class="page-header text-center">Order system</h1>
</div>
<!-- Search -->
<div class="container">
<h3 class="text-left">Search</h3>
<div class="col-md-4">
<form method="post" action="">
<div class="form-group">
<select name="search_date" class="form-control">
<option value="100000">Date</option>
<option value="100000">All time</option>
<option value="7">Last 7 days</option>
<option value="0">Today</option>
</select>
</div>
<div class="form-group">
<select name="user_id" class="form-control">
<option value="%">User</option>
<option value="1">John Smith</option>
<option value="2">Laura Stone</option>
<option value="3">Jon Olseen</option>
</select>
</div>
<div class="form-group">
<select name="product_id" class="form-control">
<option value="%">Product</option>
<option value="1">Pepsi Cola</option>
<option value="2">Coca Cola</option>
<option value="3">Fanta</option>
</select>
</div>
<div>
<button type="submit" name="search" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> Filter</button>
</div>
</form>
</div>
</div>
<!-- Order History -->
<div class="container">
<h3 class="text-left">Order History</h3>
<table class="table table-striped table-bordered">
<thead>
<th>User</th>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Date</th>
<th>Actions</th>
</thead>
<tbody>
<?php
if(isset($_POST["search"])){
$sql="SELECT * FROM orders o JOIN user u ON o.user_id=u.user_id JOIN product p ON o.product_id=p.product_id WHERE o.product_id LIKE '$_POST[product_id]' AND o.user_id LIKE '$_POST[user_id]' AND o.order_date>=DATE(NOW()) - INTERVAL '$_POST[search_date]' DAY";
}else{
$sql="SELECT * FROM orders o JOIN user u ON o.user_id=u.user_id JOIN product p ON o.product_id=p.product_id";
}
$query=$conn->query($sql);
while($row=$query->fetch_array()){
?>
<tr>
<td><?php echo $row['user_name']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['product_price']; ?></td>
<td><?php echo $row['order_quantity']; ?></td>
<td><?php echo $row['order_price']; ?></td>
<td><?php echo $row['order_date']; ?></td>
<td>
<span class="glyphicon glyphicon-pencil"></span> Edit || <span class="glyphicon glyphicon-trash"></span> Delete
<?php include('order_modal.php'); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
</html>

My view attendance table not pulling table from Database

When I attempt to view an attendance that was already filled, it brings up the table, but it is empty. My SQL and Apache error logs do not give any errors and as far as im concerned, the database table names do match.
This is my PHP code for the View All. I've also tried defining $date=date("Y-m-d); before the mysqli_query and changing the "where date=$_POST[date]" to "date=$date" but to no avail
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<form action="AttendanceTable.php" method="post">
<table class="table table-striped">
<tr>
<th>#serial Number</th> <th>Student Name</th> <th>Roll Numbers</th> <th>Attendance Status</th>
</tr>
<?php
$result=mysqli_query($con, "select * from attendance_records where date=$_POST[date]");
$serialnumber=0;
$counter=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['student_name']; ?>
</td>
<td> <?php echo $row['roll_number']; ?> </td>
<td>
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Present"> Present
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Absent"> Absent
</td>
</tr>
<?php
$counter++;
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>
This is my PHP code for the page before the view attendance
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<table class="table table-striped">
<tr>
<th>Serial Number</th> <th>Dates</th> <th>Show Attendance</th>
</tr>
<?php
$result=mysqli_query($con, "SELECT distinct date FROM attendance_records");
$serialnumber=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['date']; ?> </td>
<td>
<form action="show_attendance.php" method="POST">
<input type="hidden" value="<?php echo $row['date'] ?>" name="date">
<input type="submit" value="Show Attendance" class="btn btn-primary">
</form>
</td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>
You don't have any quotes, so your WHERE condition
where date=$_POST[date]
is expanded to where date=2019-02-17. MySQL happily computes 2019 - 2 - 17 = 2000. No date matches that so you get back zero records.
You should use a prepared statement for queries that take parameters like this, that way the database adds the necessary quotes and escape sequences http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

Session is not storing variables in PHP?

I'm facing dilemma that the session I created to store the varibale(the user name) is not showing. I want to show the user name in the maindash.html after when the user sign up in index.php.
maindash.html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
MY SITE PLANNER | DASHBOARD
</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"\>
<link href="custom.css" rel="stylesheet" type="text/css" />
</head>
<body class="formbg">
<div class="container-fluid pi">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<p class="ppp">
<img src="image/my-site-planner-logo.png" class="ppp" />
</p>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<p class="up">
<!-- Hi, user -->
Hello, <?php echo $_SESSION["name"]; ?>
settings
logout
</p>
<p id="dt">
System:
</p>
</div>
</div>
</div>
<div class="container-fluid fill">
<div class="row">
<div class="col-md-12 col col-sm-12 col-xs-12">
<div class="navbar">
<ul class="nalink">
<li>
ViewIncomeStatement
</li>
<li>
View/AddSite
</li>
<li>
View/AddVendor
</li>
<li>
View/AddItem
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<h3 class="side">
Summary of your site
</h3>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<button class="btn btn-success view" name="submit" type="submit" >
View Income Statement
</button>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<thead>
<tr class="hd">
<th width="3">Sr.</th>
<th width="6">Site Name</th>
<th width="6">Incomes</th>
<th width="6">Expenses</th>
<th width="6">Payables</th>
<th width="6">Balance</th>
<th width="10">Last Week Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>SITE A </td>
<td>200000</td>
<td>110000</td>
<td>36000</td>
<td>79000</td>
<td>Completed kitchen tiles work</td>
</tr>
<tr>
<td>2</td>
<td>SITE B</td>
<td>500000</td>
<td>425000</td>
<td>88000</td>
<td>-13000</td>
<td>completed kitchen tiles work</td>
</tr>
<tr>
<td></td>
<td>TOTAL</td>
<td>700000</td>
<td>555000</td>
<td>124000</td>
<td>66000</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xm-12">
<h3 class="side">
Your to do list
</h3>
</div>
<div class="col-md-6 col-sm-6 col-xm-12">
<button class="btn btn-success view" name="submit" type="submit">
Add Item
</button>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xm-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<thead>
<tr class="hd">
<th width="3">Sr.</th>
<th width="15">Task</th>
<th width="15">Site</th>
<th width="15">Added</th>
<th width="20">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Need to co-ordinate with shahid bhai for comment bags</td>
<td>Site A</td>
<td>23-02-2016</td>
<td>
Delete Task Mark as complete
</td>
</tr>
<tr>
<td>2</td>
<td>Get registrations done</td>
<td>Site B</td>
<td>23-02-2016</td>
<td>Delete Task Mark as complete</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xm-12">
<h3 class="side">
Quick Navigation
</h3>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xm-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<tr class="hd">
<th>
<span>Select Site</span>
<select name="site" class="hig">
<option value="" selected="selected">Fetch site list</option>
<option value="site A">site A</option>
<option value="site B">site B</option>
</select>
<span class="dis">Select Operations</span>
<select name="site" class="hig">
<option value="" selected="selected">select your option</option>
<option value="option 1">View Site-wise imcome statement</option>
<option value="option 2">View Site-wise vendors</option>
<option value="option 3">View Site-wise items list</option>
<option value="option 4">List of Vendors Vs Expenses</option>
<option value="option 5">List of Item Vs Expenses</option>
<option value="option 6">List of Labours Vs Expenses</option>
<option value="option 7">List of Service Vs Expenses</option>
<option value="option 8">Payables List</option>
<option value="option 9">To-do List</option>
<option value="option 10">Work Done List</option>
</select>
<button class="btn btn-success viewl" name="submit" type="submit" >GO</button>
</th>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xm-12">
<h3 class="side">
Reporting Definations
</h3>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xm-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<tbody>
<tr class="info">
<td>View Site-wise imcome statement</td>
<td>Show Income Statement of a particular site</td>
</tr>
<tr>
<td>View Site-wise vendors</td>
<td>Show all the vandors of a perticular site</td>
</tr>
<tr class="info">
<td>View Site-wise items list</td>
<td>Show all the Items registerd in a particular</td>
</tr>
<tr>
<td>List of Vendors Vs Expenses</td>
<td>List of all vandors registerd in a perticular site vs amount paid to them</td>
</tr>
<tr class="info">
<td>List of Item Vs Expenses</td>
<td>List of all the Items used/registerd in a perticular site and the amount utilized on them</td>
</tr>
<tr>
<td>List of Labours Vs Expenses</td>
<td>List of the labours used in a perticular site and the amount paid to them</td>
</tr>
<tr class="info">
<td>List of Service Vs Expenses</td>
<td>List of the Service used in a perticular site and the amount paid to them</td>
</tr>
<tr>
<td>Payables List</td>
<td>List of Payables in perticula site</td>
</tr>
<tr class="info">
<td>To-do List</td>
<td>To-do List of a perticular site</td>
</tr>
<tr>
<td>Work Done List</td>
<td>List of Works Done on a perticular site</td>
</tr>
<tr class="info">
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
document.getElementById("dt").innerHTML = Date();
</script>
<script src="https://code.jquery.com/jquery-2.2.0.js"></script>
</body>
</html>
index.php code:
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "index";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO form ( email, password )
VALUES ( '$email', '$password')";
if ($conn->query($sql) === TRUE) {
header('Location: sign-up.html');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
if($count == 1)
{
$_SESSION['logged'] = true;
$_SESSION['username'] = $myusername;
echo "Login worked";
exit();
}
else
{
$_SESSION['logged']=false;
echo "Login failed";
exit();
}
?>
<li class='active' style='float:right;'>
<?php
if($_SESSION['logged'] == true)
{
echo $_SESSION["name"];
echo '<span>Logout</span></li>';
}
elseif($_SESSION['logged'] == false)
{
echo '<span>Login/Register</span></li>';
}
//Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM form where email = $email and password = $password";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo " Name: " . $row["name"]. ".<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
Here after the user log in, it doesn't show the user name. I want to make it as the user name should be taken from the database file and displayed in the maindash.html. But it only shows me the Hello as written in my code.
Rename your maindash.html page to have a .php extension. And at the top of the page (maindash.php i.e.) ensure you put
<?php
session_start();
?>

What the error of update function?

I development admin control panel in my system when i update some thing in category the data not updated. what the error of my code? for more help you can download my files from here http://www.mediafire.com/download/m9psmr55pib5555/update_category.rar
<form action="categories.php" method="post">
<label>Edit category</label>
<?php
/*start of select data */
if(isset($_GET['edit_cat'])){
$cat_id = $_GET['edit_cat'];
$update_cat ="SELECT * FROM categories WHERE cat_id= $cat_id";
$run_cat_id = mysqli_query($connect , $update_cat);
while($row =mysqli_fetch_assoc($run_cat_id)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_name'];
?>
<div class="form-group">
<!--to pick the value -->
<input value="<?php if(isset($cat_title)){echo $cat_title;} ?>" type="text" class="form-control" name="cat_name">
</div>
<?php }}?>
<?php
if(isset($_POST['update'])){
$cat_update = $_POST['cat_name'];
$query ="UPDATE categories SET cat_name ='{$cat_update}' WHERE cat_id ={$cat_id}";
$update_query= mysqli_query($connect , $query);
<?php
ob_start();
include("includes/header.php");
include("includes/db.php");
?>
<div id="page-wrapper">
<div class="container-fluid">
<?php
if(isset($_GET['edit_cat'])){
$cat_id = $_GET['edit_cat'];
include ("includes/update_category.php");
}
?>
</div>
<!-- end of category form -->
</div>
<!--
===========================================================================================================
-->
<!-- start of table to show categories-->
<div class="col-lg-6">
<div class="btn btn-success"><h3>categories</h3></div>
<div class="table-responsive" >
<table class="table table-bordered table-hover">
<thead>
<tr>
<th width="10px">Id</th>
<th width="400px">category title</th>
</tr>
</thead>
<tbody>
<?php
/*Select from DB to show categories in table*/
$i=1;
$query = "SELECT *FROM categories";
$run_cat = mysqli_query($connect , $query);
while($row = mysqli_fetch_assoc($run_cat)){
$cat_id = $row['cat_id'];
$cat_name =$row ['cat_name'];
?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $cat_name; ?></td>
<td><div class='btn btn-warning' name="edit_cat"><i class='fa fa-pencil-square-o fa-2'></i> Edit</div></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- end of table to show categories-->
<!-- =============================================================================
-->
</div>
</div>
</div>
</body>
</html>
if(!$update_query){
die("QUERY FAILED".mysqli_error($connect));
}
}
?>
<div class="form-group">
<input type="submit" name="update" value="submit" class="btn btn-success"/>
</div>
</form>

Categories