I am retrieving values from the database into the form for update, on the press of the submit button, the values should get updated.
Here's the code:
PostUpdate.php:
<?php
session_start();
$username=$_SESSION['uname'];
$cn=mysqli_connect("localhost", "root", "", "imedtalks");
// Define variables and initialize with empty values
$course = $category = "";
$title = $descp = "";
// Processing form data when form is submitted
if(isset($_POST["pid"]) && !empty($_POST["pid"])){
// Get hidden input value
$pid = $_POST["pid"];
// Check input errors before inserting in database
if(!empty($course) && !empty($category) && !empty($title) && !empty($descp)){
// Prepare an update statement
$sql = "UPDATE posts SET course=?, category=?, title=?, descp=? WHERE pid=?";
if($stmt = mysqli_prepare($cn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ssssi", $param_course, $param_category, $param_title, $param_descp, $param_pid);
// Set parameters
$param_course = $course;
$param_category = $category;
$param_title = $title;
$param_descp = $descp;
$param_pid = $pid;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records updated successfully. Redirect to landing page
header("location: BCAposts.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($cn);
} else{
// Check existence of id parameter before processing further
if(isset($_GET["pid"]) && !empty(trim($_GET["pid"]))){
// Get URL parameter
$pid = trim($_GET["pid"]);
//echo $pid;
// Prepare a select statement
$sql = "SELECT pid,course,category,title,descp FROM posts WHERE pid = ?";
if($stmt = mysqli_prepare($cn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_pid);
// Set parameters
$param_pid = $pid;
//echo $param_pid;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
/* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
//echo '<pre>', var_dump($row) ,'</pre>';
// Retrieve individual field value
$pid = $row['pid'];
$course = $row['course'];
$category = $row['category'];
$title = $row['title'];
$descp = $row['descp'];
} else{
// URL doesn't contain valid id. Redirect to error page
header("location: BCAposts.php");
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
// Close connection
mysqli_close($cn);
} else{
// URL doesn't contain id parameter. Redirect to error page
header("location: BCAposts.php");
exit();
}
}
?>
<html>
<head>
<title>IMEDTalks-Post-
<?php echo $title;?>
</title>
<link href="./css/bootstrap.min.css" rel="stylesheet" />
<script src="./scripts/jquery-3.3.1.min.js"></script>
<script src="./scripts/bootstrap.min.js"></script>
<style>
/* Make the image fully responsive */
.carousel-inner img {
width: 100%;
height: 30%;
}
</style>
</head>
<body>
<div id="mycarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#mycarousel" data-slide-to="0" class="active"></li>
<li data-target="#mycarousel" data-slide-to="1"></li>
<li data-target="#mycarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="./images/banner1.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img src="http://placehold.it/1200x675&text=Second+slide" alt="Second slide">
</div>
<div class="carousel-item">
<img src="http://placehold.it/1200x675&text=Third+slide" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#mycarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#mycarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<nav class="navbar navbar-expand-sm navbar-light bg-light">
<a class="navbar-brand" href="UserHomePage.html"><img src="./images/brand.png" alt="logo" style="width:40px;"></a>
<button class="navbar-toggler d-lg-none" type="button" data-toggle="collapse" data-target="#collapsibleNavId" aria-controls="collapsibleNavId" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavId">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="UserHomePage.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Official Announcements</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Discussion Forum</a>
<div class="dropdown-menu" aria-labelledby="dropdownId">
<a class="dropdown-item" href="#">BCA</a>
<a class="dropdown-item" href="MCAposts.php">MCA</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="Post.php">Quick Post</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Fun Zone</a>
<div class="dropdown-menu" aria-labelledby="dropdownId">
<a class="dropdown-item" href="Articles.html">Articles</a>
<a class="dropdown-item" href="ChitChat.html">Chit Chat</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Resource Contents</a>
<div class="dropdown-menu" aria-labelledby="dropdownId">
<a class="dropdown-item" href="#">Course Syllabus</a>
<a class="dropdown-item" href="#">Study Materials</a>
<a class="dropdown-item" href="#">Previous Year Question Papers</a>
<a class="dropdown-item" href="#">Reference Books</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="FAQ.html">FAQ</a>
</li>
<li class="nav-item">
<a class="nav-link" href="AboutUs.html">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="ContactUs.html">Contact Us</a>
</li>
</ul>
<div>
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item dropdown btn-primary">
<a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Welcome!
<?php echo $_SESSION['uname']; ?>
</a>
<div class="dropdown-menu" aria-labelledby="dropdownId">
<a class="dropdown-item" href="#">Profile</a>
<a class="dropdown-item" href="HomePage.php">Sign Out</a>
</div>
</li>
</ul>
</div>
</div>
</nav>
<br>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h2 class="text-center">Update Post</h2>
</div>
<p class="text-center">Please edit the input values and submit to update the post.</p>
<form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
<div class="form-group">
<div class="row">
<label class="col-form-label col-md-1 offset-3" for="course">Course:</label>
<div class="col-md-2">
<select name="course" class="form-control" required>
<option value="<?php echo $course;?>" selected>
<?php echo $course;?>
</option>
<option value="">Choose any:</option>
<option value="bca">BCA</option>
<option value="mca">MCA</option>
</select>
</div>
<label class="col-form-label col-md-1" for="category">Category:</label>
<div class="col-md-3">
<select name="category" class="form-control" required>
<option value="<?php echo $category;?>" selected>
<?php echo $category;?>
</option>
<option value="">Choose any:</option>
<option value="plang">Programming Language</option>
<option value="web">Web Technologies</option>
<option value="maths">Mathematics and Statistics</option>
<option value="db">Database</option>
<option value="ds">Data Structures</option>
<option value="os">Operating Systems</option>
<option value="mngmt">Management</option>
<option value="pro">Project</option>
<option value="skills">Soft Skills</option>
<option value="intern">Internships</option>
<option value="plcmnt">Placements</option>
<option value="others">Others</option>
</select>
</div>
</div>
</div>
<div class="form-group row">
<label for="title" class="col-form-label col-md-2">Title:
</label>
<div class="col-md-10">
<input type="text" class="form-control" value="<?php echo $title;?>" name="title" required>
</div>
</div>
<div class="form-group row">
<label for="desc" class="col-form-label col-md-12">Description:
</label>
<div class="col-md-12">
<textarea class="form-control" name="descp" rows="20" required><?php echo $descp;?></textarea>
</div>
</div>
<input type="hidden" name="pid" value="<?php echo $pid;?>" />
<div class="form-group row">
<div class="col-md-4 offset-4">
<a href="MCAposts.php"><button type="button" name="cancel"
class="btn-lg btn-danger">Cancel</button></a>
</div>
<div class="col-md-4">
<button type="submit" name="update" class="btn-lg btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Here, i am using pid which is being bought from the previous page where the data is listed in table format, and on the click of a button there, that data/post gets loaded into the form for editing and updating the same using the pid(primary key in my database table) Iam using bootstrap 4.
Problem i am facing:
The update operation is not performed.
No changes in the database table values.
No error shown.
I can't figure out whats going wrong here.
Related
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());
}
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:               <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.
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 have no knowledge of PHP at all and am in desperate need of help. I have trawled the web for working examples but none of them are working for me. I need to send the data in the form to an email. I have 3 php files: index.php, contact.php and thank-you.php. Both the index and the contact page have forms on them and after sending the user is directed to the thank-you.php page. I am using localhost (MAMP) but i have also uploaded the website to this domain. Please tell me what I am doing wrong. The following code is located in the contact.php file:
<!DOCTYPE html>
<html lang="en">
<head>
<title> Legal Active - Contact Us </title>
<!-- Required meta tags always come first -->
<meta charset="utf-8">
<meta name="description" content="Index">
<meta name="keywords" content="personal inury specialist, accident,
accident claims, claim, personal injury, claim today,">
<meta name="author" content="Sukhvir Singh">
<meta name="viewport" content="width=device-width, initial-scale=1,
shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="../../css/main.css">
<!-- Animate.css -->
<link rel="stylesheet" type="text/css"
href="../../css/animate.css-master/animate.min.css">
<!-- Favicon -->
<link rel='shortcut icon' href='favicon.png' type='image/x-icon'/>
<script src="http://localhost:35729/livereload.js"></script>
</head>
<body>
<!-- Header Navbar -->
<nav class="navbar navbar-header-custom navbar-header-bg-custom">
<ul class="navbar-header-icon nav navbar-nav pull-md-left">
<li class="nav-item">
<a class="nav-link navbar-header-link hidden-dm-down"
href="#">
<i class="navbar-header-link__icon--lg fa fa-facebook" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link navbar-header-link hidden-sm-down" href="https://twitter.com/search?src=typd&q=legal%20active%20ltd">
<i class="navbar-header-link__icon--lg fa fa-twitter" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link navbar-header-link hidden-sm-down" href="#">
<i class="navbar-header-link__icon--lg fa fa-instagram" aria-hidden="true"></i>
</a>
</li>
</ul>
<ul class="nav navbar-nav pull-xs-right">
<li class="nav-item hidden-md-up">
<h5 class="navbar-header-link nav-link navbar-header-link--span"> Have a Question? </h5>
<a class="nav-link navbar-header-link" href="tel:01618852353"> Call us NOW
<i class="navbar-header-link__icon fa fa-phone" aria-hidden="true"> </i> 0161 885 2353
</a>
</li>
<li class="nav-item hidden-sm-down">
<h5 class="navbar-header-link nav-link navbar-header-link--lg--span"> Have a Question? </h5>
<a class="nav-link navbar-header-link navbar-header-link--lg" href="tel:01618852353"> Call us NOW
<i class="navbar-header-link__icon--lg fa fa-phone" aria-hidden="true"> </i> 0161 885 2353
</a>
</li>
</ul>
</nav>
<!-- Navbar -->
<nav class="navbar navbar-custom bg-custom">
<button class="navbar-toggler hidden-md-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar4" aria-controls="exCollapsingNavbar2" aria-expanded="false" aria-label="Toggle navigation">
<i class="navbar__icon fa fa-bars" aria-hidden="true"></i>
</button>
<div class="collapse navbar-toggleable-sm" id="exCollapsingNavbar4">
<ul class="nav navbar-nav pull-xs-left col-xs-12">
<li class="nav-item active col-xs-12 col-md-2 offset-md-1">
<a class="nav-link" href="index.php"> HOME </a>
</li>
<li class="nav-item btn-group col-xs-12 col-md-3">
<div class="dropdown">
<button class="btn dropdown-toggle nav-link" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
TYPES OF CLAIMS
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="road-traffic-accident.html"> ROAD TRAFFIC ACCIDENTS </a>
<a class="dropdown-item" href="Slips-Trips-and-Falls.html"> SLIPS TRIPS & FALLS </a>
<a class="dropdown-item" href="accident-at-work.html"> ACCIDENT AT WORK <span class="sr-only">(current)</span> </a>
</div>
</div>
</li>
<li class="nav-item col-xs-12 col-md-3">
<a class="nav-link" href="work-with-us.html"> WORK WITH US </a>
</li>
<li class="nav-item col-xs-12 col-md-1">
<a class="nav-link" href="#"> CONTACT </a>
</li>
<li class="nav-item col-xs-12">
<a class="nav-link hidden-md-up" href="#">
<i class="nav-link__icon fa fa-facebook" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item col-xs-12">
<a class="nav-link hidden-md-up" href="https://twitter.com/search?src=typd&q=legal%20active%20ltd">
<i class="nav-link__icon fa fa-twitter" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item col-xs-12">
<a class="nav-link hidden-md-up" href="#">
<i class="nav-link__icon fa fa-instagram" aria-hidden="true"></i>
</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="contact">
<h3 class="contact__h3"> CONTACT US </h3>
<div class="contact__divider"> </div>
<div class="contact__text col-xs-12 col-md-5">
Please use the form to tell us what you are enquiring about and somebody from our team will call you shortly.
</div>
<div class="contact__form form col-xs-12 col-md-5 offset-md-1">
<form class="form-group" id="contact__form" action="thank-you.php" method="POST">
<input type="text" class="input form-control fullName" placeholder="Full Name" name="fullName">
<input type="tel" class="input form-control number tel" placeholder="Contact Number" name="contactNumber">
<input type="text" class="input form-control email" placeholder="Email Address" name="email">
<textarea class="input col-xs-12 message" placeholder="Your Message" name="message"></textarea>
<button type="submit" class="form__btn btn btn-secondary"> SEND </button>
</form>
</div>
</div>
</div>
</div>
<!-- Footer -->
<div class="container-fluid">
<div class="container-fluid">
<div class="row">
<nav class="navbar bg-footer">
<ul class="nav navbar-nav footer__nav">
<img class="footer__nav__logo col-xs-4 col-md-4 col-lg-3 pull-xs-right pull-md-left" src="../../assets/legal-active-logo-large.png" alt="Logo"/>
<li class="footer__nav-item nav-item col-xs-12 col-md-5 pull-xs-right"> Legal Active</li>
<li class="footer__nav-item nav-item col-xs-12 col-md-5 pull-xs-right"> Magnus House, 8 Ashfield Road, Cheadle, Cheshire, SK8 1BB </li>
<li class="footer__nav-item nav-item col-xs-12 col-md-5 pull-xs-right"> Registered in England & Wales - Company No. 123 4567</li>
<li class="footer__nav-item nav-item col-xs-12 col-md-12 col-lg-5 pull-xs-right"> All Rights Reserved © Legal Active </li>
</ul>
</nav>
</div>
</div>
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="../../scss/bootstrap-4/js/tests/vendor/jquery.min.js"></script>
<script src="../../scss/bootstrap-4/js/tests/vendor/tether.min.js"></script>
<script src="../../scss/bootstrap-4/dist/js/bootstrap.min.js"></script>
<script src="../../js/custom-js.js"></script>
</body>
</html>
I have now removed the php code from contact.php to thank-you.php.
Here is the code located in than-you.php:
<?php
$to_mail = "sukhy87#me.com";
$mail_sent = 0;
if(isset($_POST['submit'])){
echo "the form was submitted";
$name = trim(strip_tags($_POST['fullName']));
if($name == "")
$error = true;
$email = trim(strip_tags($_POST['email']));
if($email == "")
$error = true;
$phone = trim(strip_tags($_POST['tel']));
$message = trim(strip_tags($_POST['message']));
if($error != true){
$header = 'From: "Legal Active Website" <no-replylegalactive.co.uk>'."\r\n";
$subject = "New Enquiry";
$message = "New Contact message, received from: <br /> \n ";
$message .= "<b>Name</b> ".$name."<br /> \n";
$message .= "<b>Email</b> ".$email."<br /> \n";
$message .= "<b>Phone</b> ".$phone."<br /> \n";
$message .= "<b>message</b> ".$message."<br /> \n";
if(#mail($to_mail,$subject,$message,$header))
{
echo "mail sent";
$mail_sent = 1;
}
else echo "mail not sent";
} else {
echo 'validation error';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title> Legal Active - Contact Us </title>
<!-- Required meta tags always come first -->
<meta charset="utf-8">
<meta name="description" content="Index">
<meta name="keywords" content="personal inury specialist, accident, accident claims, claim, personal injury, claim today,">
<meta name="author" content="Sukhvir Singh">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="../../css/main.css">
<!-- Animate.css -->
<link rel="stylesheet" type="text/css" href="../../css/animate.css-master/animate.min.css">
<!-- Favicon -->
<link rel='shortcut icon' href='favicon.png' type='image/x-icon'/>
<script src="http://localhost:35729/livereload.js"></script>
</head>
<body>
<!-- Header Navbar -->
<nav class="navbar navbar-header-custom navbar-header-bg-custom">
<ul class="navbar-header-icon nav navbar-nav pull-md-left">
<li class="nav-item">
<a class="nav-link navbar-header-link hidden-sm-down" href="#">
<i class="navbar-header-link__icon--lg fa fa-facebook" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link navbar-header-link hidden-sm-down" href="https://twitter.com/search?src=typd&q=legal%20active%20ltd">
<i class="navbar-header-link__icon--lg fa fa-twitter" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link navbar-header-link hidden-sm-down" href="#">
<i class="navbar-header-link__icon--lg fa fa-instagram" aria-hidden="true"></i>
</a>
</li>
</ul>
<ul class="nav navbar-nav pull-xs-right">
<li class="nav-item hidden-md-up">
<h5 class="navbar-header-link nav-link navbar-header-link--span"> Have a Question? </h5>
<a class="nav-link navbar-header-link" href="tel:01618852353"> Call us NOW
<i class="navbar-header-link__icon fa fa-phone" aria-hidden="true"> </i> 0161 885 2353
</a>
</li>
<li class="nav-item hidden-sm-down">
<h5 class="navbar-header-link nav-link navbar-header-link--lg--span"> Have a Question? </h5>
<a class="nav-link navbar-header-link navbar-header-link--lg" href="tel:01618852353"> Call us NOW
<i class="navbar-header-link__icon--lg fa fa-phone" aria-hidden="true"> </i> 0161 885 2353
</a>
</li>
</ul>
</nav>
<!-- Navbar -->
<nav class="navbar navbar-custom bg-custom">
<button class="navbar-toggler hidden-md-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar4" aria-controls="exCollapsingNavbar2" aria-expanded="false" aria-label="Toggle navigation">
<i class="navbar__icon fa fa-bars" aria-hidden="true"></i>
</button>
<div class="collapse navbar-toggleable-sm" id="exCollapsingNavbar4">
<ul class="nav navbar-nav pull-xs-left col-xs-12">
<li class="nav-item active col-xs-12 col-md-2 offset-md-1">
<a class="nav-link" href="index.php"> HOME </a>
</li>
<li class="nav-item btn-group col-xs-12 col-md-3">
<div class="dropdown">
<button class="btn dropdown-toggle nav-link" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
TYPES OF CLAIMS
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="road-traffic-accident.html"> ROAD TRAFFIC ACCIDENTS </a>
<a class="dropdown-item" href="Slips-Trips-and-Falls.html"> SLIPS TRIPS & FALLS </a>
<a class="dropdown-item" href="accident-at-work.html"> ACCIDENT AT WORK <span class="sr-only">(current)</span> </a>
</div>
</div>
</li>
<li class="nav-item col-xs-12 col-md-3">
<a class="nav-link" href="work-with-us.html"> WORK WITH US </a>
</li>
<li class="nav-item col-xs-12 col-md-1">
<a class="nav-link" href="contact.php"> CONTACT </a>
</li>
<li class="nav-item col-xs-12">
<a class="nav-link hidden-md-up" href="#">
<i class="nav-link__icon fa fa-facebook" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item col-xs-12">
<a class="nav-link hidden-md-up" href="https://twitter.com/search?src=typd&q=legal%20active%20ltd">
<i class="nav-link__icon fa fa-twitter" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item col-xs-12">
<a class="nav-link hidden-md-up" href="#">
<i class="nav-link__icon fa fa-instagram" aria-hidden="true"></i>
</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="submitMessage col-xs-12">
<h5 class="submitMessage__h5 h5"> THANK YOU </h5>
<p class="submitMessage__p p"> A member of our team will be in touch with you shortly </p>
<a class="submitMessage__link link" href="index.php"> Back to homepage </a>
</div>
</div>
</div>
<!-- Footer -->
<div class="container-fluid">
<div class="container-fluid">
<div class="row">
<nav class="navbar bg-footer">
<ul class="nav navbar-nav footer__nav">
<img class="footer__nav__logo col-xs-4 col-md-4 col-lg-3 pull-xs-right pull-md-left" src="../../assets/legal-active-logo-large.png" alt="Logo"/>
<li class="footer__nav-item nav-item col-xs-12 col-md-5 pull-xs-right"> Legal Active</li>
<li class="footer__nav-item nav-item col-xs-12 col-md-5 pull-xs-right"> Magnus House, 8 Ashfield Road, Cheadle, Cheshire, SK8 1BB </li>
<li class="footer__nav-item nav-item col-xs-12 col-md-5 pull-xs-right"> Registered in England & Wales - Company No. 123 4567</li>
<li class="footer__nav-item nav-item col-xs-12 col-md-12 col-lg-5 pull-xs-right"> All Rights Reserved © Legal Active </li>
</ul>
</nav>
</div>
</div>
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="../../scss/bootstrap-4/js/tests/vendor/jquery.min.js"></script>
<script src="../../scss/bootstrap-4/js/tests/vendor/tether.min.js"></script>
<script src="../../scss/bootstrap-4/dist/js/bootstrap.min.js"></script>
<script src="../../js/custom-js.js"></script>
</body>
</html>
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...