my file upload code
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lumino - Dashboard</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/datepicker3.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<link href="css/admin.css" rel="stylesheet">
<!--Custom Font-->
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<style>
.import {
right: -430px !important;
padding: 25px!important;
}
#media (max-width: 768px) {
.import {
right: 0px !important;
}
.navbar-fixed-bottom,
.navbar-fixed-top {
right: 86px!important;
left: 0;
z-index: 1030;
}
}
</style>
</head>
<body>
<?php include('dbc.php');?>
<nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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="#"> <span>Lumino</span>Admin</a>
<ul class="nav navbar-top-links navbar-right">
<li class="dropdown">
<a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
<em class="fa fa-envelope"></em>
</a>
<ul class="dropdown-menu dropdown-messages">
<li>
<div class="dropdown-messages-box">
<a href="profile.html" class="pull-left">
<img alt="image" class="img-circle" src="http://placehold.it/40/30a5ff/fff">
</a>
<div class="message-body">
<small class="pull-right">3 mins ago</small>
<strong>John Doe</strong> commented on <strong>your photo</strong>.
<br/>
<small class="text-muted">1:24 pm - 25/03/2015</small>
</div>
</div>
</li>
<li class="divider"></li>
<li>
<div class="dropdown-messages-box">
<a href="profile.html" class="pull-left">
<img alt="image" class="img-circle" src="http://placehold.it/40/30a5ff/fff">
</a>
<div class="message-body">
<small class="pull-right">1 hour ago</small>
New message from <strong>Jane Doe</strong>.
<br/>
<small class="text-muted">12:27 pm - 25/03/2015</small>
</div>
</div>
</li>
<li class="divider"></li>
<li>
<div class="all-button">
<em class="fa fa-inbox"></em> <strong>All Messages</strong>
</div>
</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
<em class="fa fa-bell"></em>
</a>
<ul class="dropdown-menu dropdown-alerts">
<li>
<a href="#">
<div><em class="fa fa-envelope"></em> 1 New Message
<span class="pull-right text-muted small">3 mins ago</span></div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<em class="fa fa-heart"></em> 12 New Likes <span class="pull-right ext-muted small">4 mins ago</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<em class="fa fa-user"></em> 5 New Followers <span class="pull-right text-muted small">4 mins ago</span>
</div>
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- /.container-fluid -->
</nav>
<div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
<div class="profile-sidebar">
<div class="profile-userpic">
<img src="http://placehold.it/50/30a5ff/fff" class="img-responsive" alt="">
</div>
<div class="profile-usertitle">
<div class="profile-usertitle-name">Username</div>
<div class="profile-usertitle-status"><span class="indicator label-success"></span>Online</div>
</div>
<div class="clear"></div>
</div>
<div class="divider"></div>
<form role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
</form>
<ul class="nav menu">
<li class="active"><em class="fa fa-dashboard"> </em> Dashboard</li>
<li><em class="fa fa-calendar"> </em> Widgets</li>
<li><em class="fa fa-bar-chart"> </em> Charts</li>
<li><em class="fa fa-toggle-off"> </em> UI Elements</li>
<li><em class="fa fa-clone"> </em> Alerts & Panels</li>
<li class="parent ">
<a data-toggle="collapse" href="#sub-item-1">
<em class="fa fa-navicon"> </em> Multilevel
<span data-toggle="collapse" href="#sub-item-1" class="icon pull-right"><em class="fa fa-plus"></em></span>
</a>
<ul class="children collapse" id="sub-item-1">
<li>
<a class="" href="#">
<span class="fa fa-arrow-right"> </span> Sub Item 1
</a>
</li>
<li>
<a class="" href="#">
<span class="fa fa-arrow-right"> </span> Sub Item 2
</a>
</li>
<li>
<a class="" href="#">
<span class="fa fa-arrow-right"> </span> Sub Item 3
</a>
</li>
</ul>
</li>
<li><em class="fa fa-power-off"> </em> Logout</li>
</ul>
</div>
<!--/.sidebar-->
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2
main">
<div class="row">
<ol class="breadcrumb">
<li>
<a href="#">
<em class="fa fa-home"></em>
</a>
</li>
<li class="active">Dashboard</li>
</ol>
</div>
<!--/.row-->
</div>
<div class="container">
<form method="post" role="form" class="impfile">
<h1 class="text-center">IMPORT FILE</h1>
<p class="search_input col-sm-12 import">
<input type="file" placeholder="From Date" id="file" name="file" required class="input-control" />
<br>
<input type="submit" name="import" value="import" id="import" class="btn btn-primary pull-center">
</p>
</form>
</div>
<?php error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE) ?>
<?php
if(isset($_POST["import"])) {
ini_set('max_execution_time', 120); //300 seconds = 5 minutes
//$filename = $_FILES['file']['name'];
$file = $_FILES['file']['tmp_name'];
//$ext=substr($file,strrpos($file,"."),(strlen($file)-
strrpos($file,".");
//if($ext=="csv")
$handle = fopen($file, "r");
//$c = 0;
while(($filesop = fgetcsv($handle,",")) !== false)
{
$category = mysqli_real_escape_string($conn,$filesop[0]);
$tags = mysqli_real_escape_string($conn,$filesop[1]);
$title = mysqli_real_escape_string($conn,$filesop[2]);
$url =mysqli_real_escape_string($conn,$filesop[3]);
$description = mysqli_real_escape_string($conn,$filesop[4]);
$date = mysqli_real_escape_string($conn,$filesop[5]);
//print_r($filesop[0]);
var_dump($filesop);
//echo $filesop[0];
$sql = "insert into report(category,tags,title,url,description,date) values ('$category','$tags','$title','$url','$description','$date')";
//$c = $c + 1;
$result=mysqli_query($conn,$sql)or die($sql."<br/><br/>".mysql_error());
//echo $sql;
//echo $filesop[1];
//echo "success";
exit();
}
//if($result){
//echo " upload success";
//ini_set('auto_detect_line_endings',FALSE);
fclose($handle);
// }
//else
// echo "cannot upload csv file";
}
mysqli_close($conn);
?>
<!--/.main-->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/chart.min.js"></script>
<script src="js/chart-data.js"></script>
<script src="js/easypiechart.js"></script>
<script src="js/easypiechart-data.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/custom.js"></script>
<script>
window.onload = function() {
var chart1 = document.getElementById("line-
chart ").getContext("
2 d ");
window.myLine = new Chart(chart1).Line(lineChartData, {
responsive: true,
scaleLineColor: "rgba(0,0,0,.2)",
scaleGridLineColor: "rgba(0,0,0,.05)",
scaleFontColor: "#c5c7cc"
});
};
</script>
</body>
</html>
Below is my csv file data.
Marketing & Customer Analytics,Trends & Product Updates,Segment Launches Segment Select,https://martechseries.com/analytics/customer-data-platforms/segment-launches-segment-select-new-program-help-companies-leverage-first-party-data-certified-partners/,"Segment, the customer data infrastructure company, launched Segment Select, a new program designed to help Channel and Technology Partners easily build and implement solutions for their customers that leverage Segment’s Customer Data Infrastructure (CDI).",2/24/2019
My database table screenshort
You have missed form attribute enctype.
You need to update in form attribute enctype in the form tag.
Your current syntax is:- <form method="post" role="form" class="impfile">
Need to update with :- <form method="post" role="form" class="impfile" enctype="multipart/form-data">
Please check below code:
<form method="post" role="form" class="impfile" enctype="multipart/form-data">
<h1 class="text-center">IMPORT FILE</h1>
<p class="search_input col-sm-12 import">
<input type="file" placeholder="From Date" id="file" name="file" required class="input-control" />
<br>
<input type="submit" name="import" value="import" id="import" class="btn btn-primary pull-center">
</p>
</form>
Updated
Update for If CSV file contains 2 or more rows. Please check below code
while (($row = fgetcsv($handle, ",")) !== false)
{
if (empty($fields)){
$fields = $row;
continue;
}
foreach ($row as $k=>$value)
{
$results[$col][$k] = $value;
}
$col++;
unset($row);
}
if (!feof($handle))
{
echo "Error: unexpected fgets() failn";
}
fclose($handle);
foreach ($results as $key => $value) {
$category = mysqli_real_escape_string($conn,$value[0]);
$tags = mysqli_real_escape_string($conn,$value[1]);
$title = mysqli_real_escape_string($conn,$value[2]);
$url =mysqli_real_escape_string($conn,$value[3]);
$description = mysqli_real_escape_string($conn,$value[4]);
$date = mysqli_real_escape_string($conn,$value[5]);
$sql = "insert into report(category,tags,title,url,description,date) values ('$category','$tags','$title','$url','$description','$date')";
$result=mysqli_query($conn,$sql)or die($sql."<br/><br/>".mysqli_error());
}
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;
});
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
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'); ?>`
I am using the bootstrap carousel as an image gallery system, which works nicely when viewing a normal album such as 200 images or less. The owner of the site however attempted to add an album with 1472 images... Which totally crashed the system obviously as it is loading all of these images at once.
Is there a way to only load the following image when the next button is clicked? As in single loading, when required? Or if not - some idea or advice on how I can speed this system up a bit? I'd rather not have the whole page reload every single time, only the image.
Here is the current script I am using:
<?
if(!$select_first == ''){
$sql = "SELECT * FROM `new_images` WHERE `alb_ref` = '$alb_ref' AND full_link < '$select_first' ORDER BY full_link ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$image_id = $row['img_id'];
$thumb_link = $row['thumb_link'];
$full_link = $row['full_link'];
if (!file_exists($full_link)) {
$full_link = 'img/default_img.jpg';
}
$viewed_count = $row['viewed_count'];
$date_added = $row['date_added'];
$i++;
$reback = $reback - 1;
?>
<div class="item <? if($i == 1){ echo 'active'; } else { } ?>">
<!-- Set the first background image using inline CSS below. -->
<div class="fill"><img class="img-responsive" style="max-width: 100%; max-height: 80%; display: block; margin: 0 auto;" src="<? echo $full_link; ?>" alt="image"></div>
<div class="carousel-caption">
<h2>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" target="_top">
<input type="hidden" id="image_selected" name="image_selected" value="<? echo $full_link; ?>">
<?
$getPhotoinfo = mysqli_fetch_assoc(mysqli_query($conn, "SELECT album_name, venue_name, city_name FROM new_albums WHERE album_ref = '$alb_ref'"));
$photo_album_name = $getPhotoinfo['album_name'];
$photo_venue_name = $getPhotoinfo['venue_name'];
$photo_city_name = $getPhotoinfo['city_name'];
$sharelink = $main_website_domain.'/'.$full_link;
$sharedesc = '';
?>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-share" aria-hidden="true"></i> Share <span class="caret caret-up"></span>
</button>
<ul class="dropdown-menu drop-up" role="menu">
<li><i class="fa fa-facebook-square" aria-hidden="true" style="color:#06C"></i> Post to Facebook</li>
<li><i class="fa fa-envelope-o" aria-hidden="true" style="color:#939"></i> Send as Email</li>
<li><i class="fa fa-floppy-o" aria-hidden="true" style="color:#090"></i> Save as Favourite</li>
<li class="divider"></li>
<li><i class="fa fa-flag" aria-hidden="true" style="color:#F00"></i> Report Photo</li>
</ul>
</div>
<button type="submit" id="download" name="download" class="btn btn-success"><i class="fa fa-download" aria-hidden="true"></i> Download</button>
<i class="fa fa-chevron-circle-left" aria-hidden="true"></i> Back
</form>
</h2>
<p style="color:#666">Image <? echo $starter - $reback; ?> / <? echo $rowcount_total_images; ?></p>
</div>
</div>
<?
}
}
}
?>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="icon-prev" style="color:#03C; font-size:70px;"></span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="icon-next" style="color:#03C; font-size:70px;"></span>
</a>
</header>
Loading the images only when requested will require a "lazy-load" technique. The basic principle is to pre-load the first image, but not the rest. Then use some JS to load the others on demand. As TWBS uses jQuery it's relatively easy to do with this code:
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<!-- load the first image -->
<img src="http://lorempixel.com/640/480/cats/1">
</div>
<div class="item">
<!-- don't load the rest -->
<img src="your-wait-icon-here.gif" data-lazy-load-src="http://lorempixel.com/640/480/cats/2">
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
</a>
</div>
$('#carousel-example-generic').on('slide.bs.carousel', function(e) {
$(e.relatedTarget).find('img').each(function() {
var $this = $(this);
var src = $this.data('lazy-load-src');
if (typeof src !== "undefined" && src != "") {
$this.attr('src', src)
$this.data('lazy-load-src', ''); // clean up
}
});
});
See this JSFiddle for an example.
The thing to remember however is that your 1472 image problem will not fix itself. It's crashing because your browser is running out of memory. With the lazy-load it will work with the first bunch but your browser will soon run out of memory. You may need to limit the amount of images loaded here...