Warning: Cannot modify header information, what is wrong in my code - php

enter image description here
what is wrong in my code, when every i try to delete a record its giving warning message ..... please help me
Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs\CMS\admin\Categories.php:10) in
C:\xampp\htdocs\CMS\admin\Categories.php on line 181
<div id="wrapper">
<!-- Navigation -->
<?php include "includes/Navigation.php";?>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li> Home Page </li>
<li class="dropdown">
<i class="fa fa-user"></i> John Smith <b class="caret"></b>
<ul class="dropdown-menu">
<li>
<i class="fa fa-fw fa-user"></i> Profile
</li>
<li class="divider"></li>
<li>
<i class="fa fa-fw fa-power-off"></i> Log Out
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li>
<i class="fa fa-fw fa-dashboard"></i> Dashboard
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> posts <i class="fa fa-fw fa-caret-down"></i>
<ul id="posts_dropdown" class="collapse">
<li>
view all pasts
</li>
<li>
add posts
</li>
</ul>
</li>
<li>
<i class="fa fa-fw fa-wrench"></i> Categories
</li>
<li>
<i class="fa fa-fw fa-file"></i> Comments
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> Users <i class="fa fa-fw fa-caret-down"></i>
<ul id="demo" class="collapse">
<li>
Dropdown Item
</li>
<li>
Dropdown Item
</li>
</ul>
</li>
<li>
<i class="fa fa-fw fa-dashboard"></i> Profile
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Welcome to Admin
<small> Rajsekhar</small>
</h1>
<div class="col-xs-6">
<?php
if(isset($_POST['submit']))
{
$cat_title = $_POST['cat_title'];
if ($cat_title == "" || empty($cat_title)) {
# code...
echo "this field should not be empty ";
} else {
$query = "INSERT INTO category(cat_title) VALUES ('{$cat_title}')";
$create_cat_query = mysqli_query($connection,$query);
if(!$create_cat_query){
die('query failed' . mysqli_error($connection));
}
}
}
?>
<form action="" method="POST">
<div class="form-group">
<label for="cat-title">Add Category</label>
<input type="text" class="form-control" name="cat_title">
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary" value="Add Category">
</div>
</form>
</div>
<!-- Add category form -->
<div class="col-xs-6">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>category title</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM category;";
$slect_all_category = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($slect_all_category)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<tr>";
echo "<td> {$cat_id}</td>";
echo "<td> {$cat_title}</td>";
echo "<td> <a href = 'Categories.php?delete={$cat_id}'> Delete </a>";
echo "</tr>";
}
?>
<tr>
</tr>
</tbody>
</table>
<?php
if(isset($_GET['delete']))
{
$delete_id = $_GET['delete'];
$query = "DELETE FROM Category where cat_id = {$delete_id} ";
$delete_query = mysqli_query($connection,$query);
header("Location: Categories.php");
if(!$delete_query)
{
die('Query Failed' . mysqli_error($connection) );
}
}
?>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->

Move your post logic at the beginning of the page.
Once the html part of your script starts it automatically starts pushing data to the browser and the headers of the response should go first. Then you include some php file that probably wants to return an error to the browser but the output has already started and so the headers can't be modified so the php gives this error
<?php
if(isset($_GET['delete']))
{
$delete_id = $_GET['delete'];
$query = "DELETE FROM Category where cat_id = {$delete_id} ";
$delete_query = mysqli_query($connection,$query);
header("Location: Categories.php");
if(!$delete_query)
{
die('Query Failed' . mysqli_error($connection) );
}
}
?>
//rest of the page

Related

After clicking the submit button in a form, everything became undefined

Hi. Everything is working perfectly until I clicked the submit button.
This is what it looks like before clicking the submit button. But after clicking it, this is what it will look like. After clicking it, all the information became undefined. Can someone please help me.
I dont know what went wrong. Here is my code.
<?php
session_start();
if(!isset($_SESSION["user"]))
{
header("location:index.php");
}
ob_start();
include ('db.php');
$pid = $_GET['pid'];
$sql ="select * from reservation where reservationno = '$pid' ";
$re = mysqli_query($con,$sql);
while($row=mysqli_fetch_array($re))
{
$clientid = $row['clientid'];
$name = $row['name'];
$reservationno = $row['reservationno'];
$invoiceno = $row['invoiceno'];
$reservationdate = $row['reservationdate'];
$totalamount = $row['totalamount'];
$netamount = $row['netamount'];
$cin = $row['reservefrom'];
$cout = $row['reserveto'];
}
$asql ="select * from reservationdetails where reservationno = '$pid' ";
$are = mysqli_query($con,$asql);
while($row=mysqli_fetch_array($are))
{
$cout2 = $row['checkout2'];
$cout3 = $row['checkout3'];
$days = $row['days'];
$days2 = $row['days2'];
$days3 = $row['days3'];
$roomid = $row['roomid'];
$roomid2 = $row['roomid2'];
$roomid3 = $row['roomid3'];
$qty = $row['qty'];
$qty2 = $row['qty2'];
$qty3 = $row['qty3'];
}
?>
<div id="wrapper">
<nav class="navbar navbar-default top-navbar" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="home.php"><?php echo $_SESSION["user"]; ?> </a>
</div>
<ul class="nav navbar-top-links navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
<i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><i class="fa fa-user fa-fw"></i> User Profile
</li>
<li><i class="fa fa-gear fa-fw"> </i> Settings
</li>
<li class="divider"></li>
<li><i class="fa fa-sign-out fa-fw"></i> Logout
</li>
</ul>
<!-- /.dropdown-user -->
</li>
<!-- /.dropdown -->
</ul>
</nav>
<!--/. NAV TOP -->
<nav class="navbar-default navbar-side" role="navigation">
<div class="sidebar-collapse">
<ul class="nav" id="main-menu">
<li>
<i class="fa fa-dashboard"></i> Status
</li>
<li>
<i class="fa fa-desktop"></i> News Letters
</li>
<li>
<i class="fa fa-bar-chart-o"></i>Room Booking
</li>
<li>
<a class="active-menu" href="Payment.php"><i class="fa fa-qrcode"></i> Payment</a>
</li>
<li>
<i class="fa fa-qrcode"></i> Reports
</li>
<li>
</i> Logout
</li>
</div>
</nav>
<!-- /. NAV SIDE -->
<div id="page-wrapper" >
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<h3 class="page-header">
Update Payment
</h3>
</div>
</div>
<!-- /. ROW -->`
<?php
include('db.php');
$mail = "SELECT * FROM `contact`";
$rew = mysqli_query($con,$mail);
?>
<div class="row">
<div class="col-md-12">
<div class="jumbotron">
<div class="panel-body">
<form>
<?php echo $clientid; ?><br>
<?php echo $name; ?><br>
Invoice no: <?php echo $invoiceno; ?><br>
Total Amount: ₱<?php echo $totalamount; ?><br>
Remaining Balance:
<br><br><br>
<h5>Payment: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<h5>
<input type="text" name="updatetextbox" /><br><br>
<h5>Confirm Payment:</h5>
<input type="text" name="updatetextbox1" />
<br>
<center><input type="submit" class="btn btn-primary" />
<?php
if(isset($_POST['submit'])){
$code1=$_POST['updatetextbox1'];
$code=$_POST['updatetextbox'];
if($code1!="$code"){
//$msg="Invalid code";
echo "<script type='text/javascript'> alert('Error')</script>";
}
else
$curdate=date("Y/m/d");
$paymentmode = "Cash";
$amountpaid_cash = 1.00;
$paymentdetails = "INSERT INTO `payments` (`clientid`, `name`, `reservationno`, `paymentmode`, `creditcardno`, `bankname`, `amountpaid_cc`, `amountpaid_cash`, `invoiceno`, `datepaid`) VALUES ('$clientid', '$name', '$reservationno', '$paymentmode', 'NULL', 'NULL', 'NULL', '$amountpaid_cash', '$invoiceno', '$curdate')";
if (mysqli_query($con,$paymentdetails))
{
echo "<script type='text/javascript'> alert('Your Booking application has been sent')</script>";
}
else
{
echo "<script type='text/javascript'> alert('Error adding user in database')</script>";
}
}
?>
</form>
</div>
</div>
</div>
<?php
$sql = "SELECT * FROM `contact`";
$re = mysqli_query($con,$sql);
?>
<!-- /. ROW -->
</div>
</div>
</div>
<!-- /. PAGE INNER -->
</div>
The problem is that you don't pass any of that information to the page after you submit it. Your first example shows pid as an HTTP get variable and that's what you use to define everything else. In your second example (after submit), there is no pid variable. Your code has no way to get the information unless you pass it along with the submit request or you include pid again, so that it can do the same lookup.
for those who came too late here is the answer to this question
you just need to put the insertion statement inside the :
This image will explain the solution
this happened because of the scope of the variables can't be reached outside the if statement block.

Ajax php page and url change on load using load() function without refreshing

I am recently Creating a Blog site and it is based on php version 5.6.Now I am stuck over a week to achieve "ajax page load as well as url changing when click on navigation without refreshing the entire page". I have followed many suggestion from stakeoverflow and jQuery Forum.But own't make it properly. I have menu with dropdown and also have dropdown-toggle data attribute. Somtimes my code works fine but dropdown and dropdown-togglewon't work. Can anyone give me the way to achieve this.I am just a beginner of ajax. Here is my code.
header.php
<?php
require_once "../vendor/autoload.php";
include "../lib/Database.php";
include "../config/config.php";
include "../helpers/Format.php";
$fm= new Format();
$db = new Database();
$query ="SELECT * FROM `tbl_post` LIMIT 5";
$post = $db->select($query);
?>
<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<?php include '../scripts/meta.php';?>
<?php include '../scripts/css.php';?>
<?php include "../scripts/js.php";?>
</head>
<style>
.row{
margin:0;
}
</style>
<body>
<!-- header starts -->
<header>
<section id="smedia">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 navbar-left">
<p>PHONE: 01971982959 </p>
</div>
<div class="col-sm-4">
<?php
$slgQuery = "SELECT * FROM `tbl_social` WHERE `id`= '1'";
$socialMedia = $db->select($slgQuery);
if($socialMedia )
{
while($socialResult = $socialMedia->fetch_assoc()) {
?>
<i class="fa fa-facebook-official" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-pinterest-p" aria-hidden="true"></i>
<i class="fa fa-google-plus" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
<?php
}
}
?>
</div>
</div>
</div>
</section>
<!-- Navbar Starts -->
<div class="row">
<nav class="navbar navbar-default">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../Template/index.php">
<?php
$slgQuery = "SELECT * FROM `title_slogan` WHERE `id`= '1'";
$getTitle = $db->select($slgQuery);
if($getTitle)
{
while($slgResult = $getTitle->fetch_assoc())
{
?>
<img src="../Dashboard/admin/<?php echo $slgResult['logo'];?>" alt="logo" class="img-responsive">
<?php
}
}
?>
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<?php
$path = $_SERVER['SCRIPT_FILENAME'];
$currentPage = basename($path,'.php');
?>
<li <?php if($currentPage == 'index'){echo 'class ="active"';}?>>Home <span class="sr-only">(current)</span></li>
<li <?php if($currentPage == 'Excellent'){echo 'class ="active"';}?>>
Post<span class="caret"></span>
<ul class="dropdown-menu" aria-labelledby="dLabel">
<?php
if ($post){
while($result = $post->fetch_assoc())
{
?>
<li><p><?php echo $result['title'];?></p></li>
<?php }
}else{
echo "data not Found!!";
}?>
</ul>
</li>
<?php
$aboutQuery = "select * from `tbl_page`";
$navigation = $db->select($aboutQuery);
if ($navigation)
{
while($aboutResult = $navigation->fetch_assoc())
{
?>
<li id="nav_link"
<?php if (isset($_GET['pageid'])&& $_GET['pageid']== $aboutResult['id'])
{
echo 'class ="active"';
}
?>
> <a href="../Template/page.php?pageid=<?php echo $aboutResult['id'];?>"><?php echo $aboutResult['name'];?>
</a>
</li>
<?php
}
}
?>
<li <?php if($currentPage == 'contact'){echo 'class ="active"';}?> >Contact</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
<!-- Navbar Ends -->
</header>
<!-- header ended -->
js.php
$('#nav_link li a').click(function (e) {
e.preventDefault();
var navPage=$(this).attr('href');
// alert(navPage);
$(document.body).load(navPage).fadeIn('slow');
$('.dropdown-toggle').dropdown();
if(navPage!==location.href){
window.history.pushState({path:navPage},'',navPage);
}
return false;
});
Any help will be appriciate or please enlighten me.Thanks in advence
Update
HERE IS THE UPDATE
header.php
<?php
// require_once "../vendor/autoload.php";
include "../lib/Database.php";
include "../config/config.php";
include "../helpers/Format.php";
$fm= new Format();
$db = new Database();
$query ="SELECT * FROM `tbl_post` LIMIT 5";
$post = $db->select($query);
?>
<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<?php include '../scripts/meta.php';?>
<?php include '../scripts/css.php';?>
</head>
<style>
.row{
margin:0;
}
</style>
<body>
<!-- header starts -->
<header>
<section id="smedia">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 navbar-left">
<p>PHONE: 01971982959 </p>
</div>
<div class="col-sm-4">
<?php
$slgQuery = "SELECT * FROM `tbl_social` WHERE `id`= '1'";
$socialMedia = $db->select($slgQuery);
if($socialMedia )
{
while($socialResult = $socialMedia->fetch_assoc()) {
?>
<i class="fa fa-facebook-official" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-pinterest-p" aria-hidden="true"></i>
<i class="fa fa-google-plus" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
<?php
}
}
?>
</div>
</div>
</div>
</section>
<!-- Navbar Starts -->
<div class="row">
<nav class="navbar navbar-default">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../Template/index.php">
<?php
$slgQuery = "SELECT * FROM `title_slogan` WHERE `id`= '1'";
$getTitle = $db->select($slgQuery);
if($getTitle)
{
while($slgResult = $getTitle->fetch_assoc())
{
?>
<img src="../Dashboard/admin/<?php echo $slgResult['logo'];?>" alt="logo" class="img-responsive">
<?php
}
}
?>
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right nav_link">
<?php
$path = $_SERVER['SCRIPT_FILENAME'];
$currentPage = basename($path,'.php');
?>
<li <?php if($currentPage == 'index'){echo 'class ="active"';}?>>Home <span class="sr-only">(current)</span></li>
<li <?php if($currentPage == 'Excellent'){echo 'class ="active"';}?>>
Post<span class="caret"></span>
<ul class="dropdown-menu nav_link" aria-labelledby="dLabel">
<?php
if ($post){
while($result = $post->fetch_assoc())
{
?>
<li><p><?php echo $result['title'];?></p></li>
<?php }
}else{
echo "data not Found!!";
}?>
</ul>
</li>
<?php
$aboutQuery = "select * from `tbl_page`";
$navigation = $db->select($aboutQuery);
if ($navigation)
{
while($aboutResult = $navigation->fetch_assoc())
{
?>
<li
<?php if (isset($_GET['pageid'])&& $_GET['pageid']== $aboutResult['id'])
{
echo 'class ="active"';
}
?>
> <a href="../Template/page.php?pageid=<?php echo $aboutResult['id'];?>"><?php echo $aboutResult['name'];?>
</a>
</li>
<?php
}
}
?>
<li <?php if($currentPage == 'contact'){echo 'class ="active"';}?> >Contact</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
<!-- Navbar Ends -->
</header>
<!-- header ended -->
js.php
$('.nav_link li a').click(function (e) {
e.preventDefault();
var navPage= $(this).attr('href');
//alert(navPage);
$(document.body).load(navPage).fadeIn('slow');
$(".dropdown-toggle").dropdown();
if(navPage!==location.href){
window.history.pushState({path:navPage},'',navPage);
}
return false;
});
Very First remove the id="nav_link" from <li> and add then add class on <ul>
I will recommend that you one class and to add on your both <ul>
From: <ul class="nav navbar-nav navbar-right">
To: <ul class="nav navbar-nav navbar-right nav_link">
Also for the secound <ul>
Add same class
Now change in the jquery
from: $('#nav_link li a').click(function (e) {
To: $('.nav_link li a').click(function (e) {
As # is for Id and . is for Class Learn more about this at here: Selector
Extra Update
There are a lot of ways to do this but will let you know the one which is useful with current code
you need to stop the jquery code if there is # in the URL and that is for post menu
$('.nav_link li a').click(function (e) {
e.preventDefault();
var navPage= $(this).attr('href');
if(navPage != "#"){
// your code
}
return false;
});

how can i pass my variable to my modal?

I'm having a hard time on passing my variable to my modal.
I can't simply pass my informant id to my modal and I really would want to use it for my query as my base to search for or compare it.
I don't know how to pass it like the URL passing of variable using GET function and I'm really new to this and just wanted to try modal unlike creating a new page for a summary.
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=deviceADMIN | Missing Person Tracking System-width, initial-scale=1.0" />
<title>ADMIN | Missing Person Tracking System </title>
<!-- Bootstrap Styles-->
<link href="assets/css/bootstrap.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- FontAwesome Styles-->
<link href="assets/css/font-awesome.css" rel="stylesheet" />
<!-- Morris Chart Styles-->
<link href="assets/js/morris/morris-0.4.3.min.css" rel="stylesheet" />
<!-- Custom Styles-->
<link href="assets/css/custom-styles.css" rel="stylesheet" />
<!-- Google Fonts-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
</head>
<body>
<div id="wrapper">
<nav class="navbar navbar-default top-navbar" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php"><i class="fa fa-shield"></i> <strong>POLICE ADMIN </strong></a>
</div>
<ul class="nav navbar-top-links navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
<i class="fa fa-bell fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-alerts">
<li>
<a href="#">
<div>
<i class="fa fa-comment fa-fw"></i> New Comment
<span class="pull-right text-muted small">4 min</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-twitter fa-fw"></i> 3 New Followers
<span class="pull-right text-muted small">12 min</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-envelope fa-fw"></i> Message Sent
<span class="pull-right text-muted small">4 min</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-tasks fa-fw"></i> New Task
<span class="pull-right text-muted small">4 min</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-upload fa-fw"></i> Server Rebooted
<span class="pull-right text-muted small">4 min</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a class="text-center" href="#">
<strong>See All Alerts</strong>
<i class="fa fa-angle-right"></i>
</a>
</li>
</ul>
<!-- /.dropdown-alerts -->
</li>
<!-- /.dropdown -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
<i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><i class="fa fa-sign-out fa-fw"></i> Logout
</li>
</ul>
<!-- /.dropdown-user -->
</li>
<!-- /.dropdown -->
</ul>
</nav>
<!--/. NAV TOP -->
<nav class="navbar-default navbar-side" role="navigation">
<div id="sideNav" href=""><i class="fa fa-caret-right"></i></div>
<div class="sidebar-collapse">
<ul class="nav" id="main-menu">
<li>
<i class="fa fa-dashboard"></i> Dashboard
</li>
<li>
<i class="fa fa-user"></i> Missing Person Management
</li>
<li>
<i class="fa fa-plus"></i> Create Account</span>
</li>
<li>
<i class="fa fa-sitemap"></i> Manage Services <span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li>
News
</li>
<li>
Contacts
</li>
</ul>
</li>
<li>
<a class="active-menu" href="#"><i class="fa fa-sitemap"></i> Transactions <span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li>
<<a class="active-menu" href="transac_pending.php"> Pending</a>
</li>
<li>
Verified
</li>
<li>
Rejected
</li>
</ul>
</li>
<li>
<i class="fa fa-file"></i> Reports
</li>
<li>
<i class="fa fa-history"></i> Audit Trail
</li>
</ul>
</div>
</nav>
<!-- /. NAV SIDE -->
<div id="page-wrapper" >
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<h1 class="page-header">
Transaction Requests
</h1>
</div>
</div>
<!-- /. ROW -->
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<ol class="breadcrumb">
<li class="active">
<i class="fa fa-user"></i> List of Transaction Requests
</li>
</ol>
</div>
<div class="panel-body">
<div class="column" >
<tr>
<td>
<table class="table table-hover" border="2">
<col width="5%"></col>
<col width="15%"></col>
<col width="10%"></col>
<col width="10%"></col>
<col width="10%"></col>
<col width="15%"></col>
<col width="15%"></col>
<col width="10%"></col>
<thead>
<tr>
<center>
<th><center>Informant Name</th>
<th><center>Informant Address</th>
<th><center>Informant Contact</th>
<th><center>Informant Email</th>
<th><center>Sighted Person</th>
<th><center>Action</th>
</center>
</tr>
</thead>
<?php
include('mysql_connect.php');
$query="SELECT * from tbl_informant,tbl_missing_person where informant_status='Pending' and reported_id=mp_id";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><center><?php echo $row['informant_fname'].' '.$row['informant_lname'];?></center></td>
<td><center>
<?php echo $row['informant_address'];?></center></td>
<td><?php echo $row['informant_contact']?></td>
<td><?php echo $row['informant_email']?></td>
<td>
<img src="<?php echo $row['mp_image_location'].$row['mp_image']?>" height=100 width=100><br>
<?php echo $row['mp_fname'].' '.$row['mp_lname']?>
</td>
<td>
<?php
$id=$row['informant_id'];
$_SESSION['id']=$id;
echo "<center>
<button type='button'class='btn btn-primary btn-sm?id=".$id."' data-toggle='modal' title='Confirm'data-target='#ModalConfirm'>
Confirm</button>
<button type='button'class='btn btn-danger btn-sm?id=".$id."' data-toggle='modal' title='Confirm'data-target='#ModalReject'>
Reject</button>
</center>"
?>
</td>
</tr>
<?php
}
?>
<!-- Modal for REJECT-->
<div class="modal fade" id="ModalReject" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><b>Rejecting Request:</h4></b>
</div>
<div class="modal-body">
<p>Reason/s: </p>
<textarea cols="75" rows="5" placeholder="Enter reason here.." name="transac_reason"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Submit</button>
</div>
</div>
</div>
</div>
<!-- Modal for CONFIRM-->
<div class="modal fade" id="ModalConfirm" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<p>Are you sure you want to confirm request? </p>
<?php
$modalquery="select * from tbl_informant,tbl_missing_person,tbl_contact_person
where concat(reported_id=mp_id && mp_id=cp_id)";
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" >Yes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /. PAGE INNER -->
</div>
<!-- /. PAGE WRAPPER -->
</div>
<!-- /. WRAPPER -->
<!-- JS Scripts-->
<!-- jQuery Js -->
<script src="assets/js/jquery-1.10.2.js"></script>
<!-- Bootstrap Js -->
<script src="assets/js/bootstrap.min.js"></script>
<!-- Metis Menu Js -->
<script src="assets/js/jquery.metisMenu.js"></script>
<!-- Morris Chart Js -->
<script src="assets/js/morris/raphael-2.1.0.min.js"></script>
<script src="assets/js/morris/morris.js"></script>
<!-- Custom Js -->
<script src="assets/js/custom-scripts.js"></script>
</body>
</html>
You can't execute a live mysql query like this to modify the table.
The best way for this is with ajax, you can catch the id if is on the table and use ajax to execute the mysql query.
I suggest you put the informant id in the value of a button in the table with a class:
<button class="id" data-target="modal" value="<?= $row['informant_id'] ?>"/>
and you can get the value of the button with a jquery event with this:
$(document).on("click", "id", function(){
var id = $(this).val();
console.log(id);
// and handle the value
});
this is one of many ways to pass the variable, if you just want to print it on the modal, create a tag with an id "example" <h1 id="example"></h1> inside the modal and execute this:
$(document).on("click", "id", function(){
var id = $(this).val();
console.log(id);
// and handle the value
$(".modal #example").text(id);
});
Regards.

How to retrieve the firstname from database using session

I want to display the firstname from database who login in my website - not the username of the user.
Here's a picture of my database so I already tried query but always complains about an undefined index
This is the navbar attendance only there's a another navbar too but I only example the attendance
navbar_attendance.php
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><i class="icon-home icon-large"></i> Home</li>
<li><i class="icon-home icon-large"></i> Attendance Info</li>
<li><i class="icon-user icon-large"></i> Users</li>
<?php
include('dropdown.php');
?>
<li><i class="icon-book icon-large"></i> Books</li>
<li><i class="icon-group icon-large"></i> Member</li>
<li ><i class="icon-list-alt icon-large"></i> Archive</li>
<li><i class="icon-cog icon-large"></i> Utilities</li>
<li><i class="icon-signout icon-large"></i> Logout</li>
</ul>
<div class="pull-right">
<div class="admin">Welcome: <?php
if(isset($_SESSION['id'])){
// dont know what put in here
}
?></div>
</div>
</div>
</div>
</div>
</div>
<?php include('search_form.php'); ?>
session.php
<?php if(!isset($_SESSION)){
session_start();
} ?>
<?php
if (!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) {
?> <script>window.location='index.php';</script> <?php
exit();
}
$session_id=$_SESSION['id'];
?>
Hi you need to put this query at the place where you want to show the first name.
<?php if(!isset($_SESSION)){
session_start();
} ?>
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><i class="icon-home icon-large"></i> Home</li>
<li><i class="icon-home icon-large"></i> Attendance Info</li>
<li><i class="icon-user icon-large"></i> Users</li>
<?php
include('dropdown.php');
?>
<li><i class="icon-book icon-large"></i> Books</li>
<li><i class="icon-group icon-large"></i> Member</li>
<li ><i class="icon-list-alt icon-large"></i> Archive</li>
<li><i class="icon-cog icon-large"></i> Utilities</li>
<li><i class="icon-signout icon-large"></i> Logout</li>
</ul>
<div class="pull-right">
<div class="admin">Welcome: <?php
if(isset($_SESSION['id'])){
$sql="SELECT firstname FROM TABLENAME WHERE user_id='$session_id'";
$result=mysqli_query($link,$sql);
if(mysqli_num_rows($result)>0)
{
while($row= mysqli_fetch_assoc($result)){
echo $row['firstname'];
}
}
}
?></div>
</div>
</div>
</div>
</div>
</div>
<?php include('search_form.php'); ?>`

Hostinger error, Strict Standards Only variables should be passed by reference

<section class="vbox">
<header class="bg-dark lt header navbar navbar-fixed-top-xs">
<?php $uri = end( explode("/",$_SERVER['REQUEST_URI'])); ?>
<div class="navbar-header bg-dark aside-md"> <a class="btn btn-link visible-xs" data-toggle="class:nav-off-screen,open" data-target="#nav,html"> <i class="fa fa-bars"></i> </a> <img src="./files/logo.png" class="m-r-xs">ResidenConce <a class="btn btn-link visible-xs" data-toggle="dropdown" data-target=".nav-user"> <i class="fa fa-cog"></i> </a> </div>
<ul class="nav navbar-nav navbar-right nav-user m-n hidden-xs">
<li class="hidden-xs"> <i class="fa fa-bell"></i>
<section class="dropdown-menu aside-xl">
<section class="panel bg-white">
<header class="panel-heading b-light bg-light"> <strong>Tienes <span class="count">0</span> notificaciones</strong> </header>
</section>
</section>
</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span class="thumb-sm avatar pull-left"> <img src="./files/avatar.jpg"> </span> <?php if($_SESSION['logged_in']) { ?>
<?php echo $_SESSION['first_name']; ?> <b class="caret"></b> </a>
<ul class="dropdown-menu animated fadeInRight">
<span class="arrow top"></span>
<li> Ajustes </li>
<li class="divider"></li>
<li> Cerrar Sesión </li>
</ul>
</li>
</ul>
<?php } ?>
</header>
<section>
...
Gives me error in this line
<?php $uri = end( explode("/",$_SERVER['REQUEST_URI'])); ?>
In localhost it works, but in Hostinger it's the error
please any solution, thanks ind advance guys
end requires an array, not an expression resolved to array.
So:
<?php $uri = end( explode("/",$_SERVER['REQUEST_URI'])); ?>
should be:
<?php
$requestUriArray = explode("/",$_SERVER['REQUEST_URI'])
$uri = end($requestUriArray);
?>
end function has a parameter that passed by reference. So only need to use a variable to send this parameter:
$request_uri = explode("/",$_SERVER['REQUEST_URI']);
$uri = end($request_uri);

Categories