After setting up an Apache web server on my local machine, I've attempted to use a php document to handle uploads/downloads from the server. I used the tutorial found at:
PHP Upload/Download Tutorial
It accepts uploads as normal (after fixing a flaw with page navigation on line 21 of the index.php page ["upload.php" should be "uploads.php"]), but it doesn't display the table of uploaded files as it should. I've attached the index.php code in case something obvious stands out.
<!DOCTYPE html>
<html>
<head>
<title>Upload View & Download file in PHP and MySQL | Demo</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" >
<link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
</head>
<body>
<br/>
<div class="container">
<div class="row">
<div class="col-xs-8 col-xs-offset-2 well">
<form action="uploads.php" method="post" enctype="multipart/form-data">
<legend>Select File to Upload:</legend>
<div class="form-group">
<input type="file" name="file1" />
</div>
<div class="form-group">
<input type="submit" name="submit" value="Upload" class="btn btn-info"/>
</div>
<?php if(isset($_GET['st'])) { ?>
<div class="alert alert-danger text-center">
<?php if ($_GET['st'] == 'success') {
echo "File Uploaded Successfully!";
}
else
{
echo 'Invalid File Extension!';
} ?>
</div>
<?php } ?>
</form>
</div>
</div>
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>File Name</th>
<th>View</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($row = mysqli_fetch_array($result)) { ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row['filename']; ?></td>
<td>View</td>
<td><a href="uploads/<?php echo $row['filename']; ?>" download>Download</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
*Note: I do have the bootstrap.css files downloaded so it's not some weird visual thing as far as I can tell.
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 2 years ago.
I got an image gallery crud script and decided to make the edit image page an edit profile page. My issue is what I added doesn't redirect back to profile page. Here is my code :
<?php
// Start session
session_start();
// Include and initialize DB class
require_once 'DB.class.php';
$db = new DB();
// Fetch the users data
$images = $db->getRows('images');
// Get session data
$sessData = !empty($_SESSION['sessData'])?$_SESSION['sessData']:'';
// Get status message from session
if(!empty($sessData['status']['msg'])){
$statusMsg = $sessData['status']['msg'];
$statusMsgType = $sessData['status']['type'];
unset($_SESSION['sessData']['status']);
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>SWARZIE</title>
<meta charset="utf-8">
<!-- Bootstrap library -->
<link rel="stylesheet" href="bootstrap/bootstrap.min.css">
<!-- Stylesheet file -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<style>
.form {
width: 300px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
<h1>Image Gallery</h1>
<hr>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Swarzie</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<> <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<"></a>
</li>
<li class="nav-item">
<></a>
</li>
<li class="nav-item">
<></a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
</form>
<form class="form-inline my-2 my-lg-0">
Profile
</form>
<form class="form-inline my-2 my-lg-0">
Logout
</form>
</div>
</nav>
<?php //from ww w .j a va2 s .c om
if ( isset( $_POST["submitButton"] ) ) {
// (deal with the submitted fields here)
header( "Location: profile.php" );
exit;
} else {
displayForm();
}
function displayForm() {
?>
<!DOCTYPE html5>
<html>
<body>
<form action="profile.php">
<label for="img">Select image:</label>
<input type="file" id="img" name="img" accept="image/*">
<input type="submit">
</form>
<form action="profile.php" method="post">
<label for="firstName">First name</label>
<input type="text" name="firstName" id="firstName" value="" />
<label for="lastName">Last name</label>
<input type="text" name="lastName" id="lastName" value="" />
<textarea rows="2" cols="30" name="comment" form="usrform">
About</textarea>
<input type="submit" name="submitButton" id="submitButton" value= "Send Details" />
</form>
</body>
</html>
<?php
}
?>
<!-- Display status message -->
<?php if(!empty($statusMsg)){ ?>
<div class="col-xs-12">
<div class="alert alert-<?php echo $statusMsgType; ?>"><?php echo $statusMsg; ?></div>
</div>
<?php } ?>
<div class="row">
<div class="col-md-12 head">
<h5>Images</h5>
<!-- Add link -->
<div class="float-right">
<i class="plus"></i> New Image
</div>
</div>
<!-- List the images -->
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th width="5%"></th>
<th width="12%">Image</th>
<th width="45%">Title</th>
<th width="17%">Created</th>
<th width="8%">Status</th>
<th width="13%">Action</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($images)){
foreach($images as $row){
$statusLink = ($row['status'] == 1)?'postAction.php?action_type=block&id='.$row['id']:'postAction.php?action_type=unblock&id='.$row['id'];
$statusTooltip = ($row['status'] == 1)?'Click to Inactive':'Click to Active';
?>
<tr>
<td><?php echo '#'.$row['id']; ?></td>
<td><img src="<?php echo 'uploads/images/'.$row['file_name']; ?>" alt="" /></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['created']; ?></td>
<td><span class="badge <?php echo ($row['status'] == 1)?'badge-success':'badge-danger'; ?>"><?php echo ($row['status'] == 1)?'Active':'Inactive'; ?></span></td>
<td>
edit
delete
</td>
</tr>
<?php } }else{ ?>
<tr><td colspan="6">No image(s) found...</td></tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</body>
</html>
End result would have the form action(name, text area and profile upload)content to show up above the gallery crud on the profile.php file. How do I do this?
Thank you :)
Header function should be called before any output is made.
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. see more info in PHP.net
As you are calling header("Location...") after part of your html has been outputed, it will not work.
You should try moving the logic with the header(...) to the top of the file.
When you redirect to another page you should have to carry the value of $_POST with your page, otherwise you will get null of it. You can carry with session.
You can do it just before the statement where you redirect to another page, like
$_SESSION['post_data']=$_POST;
header('Location:profile.php'); exit;
Now you have posted data in the session.
This is my entire code to generate reports for a particular student using his/her student id.
My SQL query will show the list of books not yet returned by the student....
While debugging I noticed that if I Manually put any student ID in the code, I can see the results but the button click feature is not working ... somehow the button is not taking any data from my SQL query and not executing..
<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
{
header('location:index.php');
}
else
{
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>
Online Library Management System | Report Generation
</title>
<!-- BOOTSTRAP CORE STYLE -->
<link href="assets/css/bootstrap.css" rel="stylesheet" />
<!-- FONT AWESOME STYLE -->
<link href="assets/css/font-awesome.css" rel="stylesheet" />
<!-- DATATABLE STYLE -->
<link href="assets/js/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
<!-- CUSTOM STYLE -->
<link href="assets/css/style.css" rel="stylesheet" />
<!-- GOOGLE FONT -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
</head>
<body>
<!------MENU SECTION START-->
<?php include('includes/header.php');?>
<!-- MENU SECTION END-->
<div class="content-wrapper">
<div class="container">
<div class="row pad-botm">
<div class="col-md-12">
<h4 class="header-line">
Employee Reports
</h4>
</div>
<div class="row">
<?php if($_SESSION['error']!="")
{?>
<div class="col-md-6">
<div class="alert alert-danger" >
<strong>
Error :
</strong>
<?php echo htmlentities($_SESSION['error']);?>
<?php echo htmlentities($_SESSION['error']="");?>
</div>
</div>
<?php } ?>
<?php if($_SESSION['msg']!="")
{?>
<div class="col-md-6">
<div class="alert alert-success" >
<strong>
Success :
</strong>
<?php echo htmlentities($_SESSION['msg']);?>
<?php echo htmlentities($_SESSION['msg']="");?>
</div>
</div>
<?php } ?>
<?php if($_SESSION['delmsg']!="")
{?>
<div class="col-md-6">
<div class="alert alert-success" >
<strong>
Success :
</strong>
<?php echo htmlentities($_SESSION['delmsg']);?>
<?php echo htmlentities($_SESSION['delmsg']="");?>
</div>
</div>
<?php } ?>
</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-6 col-xs-12 col-md-offset-1"">
<div class="panel panel-info">
<div class="panel-body">
<form role="form" method="post">
<div class="form-group">
<label>
CPF NUMBER<span style="color:red;">*</span>
</label>
<input class="form-control" type="text" name="studentid" id="studentid" autocomplete="off" required />
</div>
<button type="submit" name="report" id="submit" class="btn btn-info">
Generate
</button>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<!-- Advanced Tables -->
<div class="panel panel-default">
<div class="panel-heading">
Issued Documents
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>#</th>
<th>Employee Name</th>
<th>Document Name</th>
<th>Reference Number</th>
<th>Issued Date</th>
<th>STATUS</th>
</tr>
</thead>
<tbody>
<?php
if($query->rowCount() > 0)
{
foreach($results as $result)
{
if(isset($_POST['report']))
{
$studentid=strtoupper($_POST['studentid']);
$sql = "SELECT tblstudents.FullName,tblbooks.BookName,tblbooks.ISBNNumber,tblissuedbookdetails.IssuesDate,tblissuedbookdetails.RetrunStatus,tblissuedbookdetails.id as rid from tblissuedbookdetails join tblstudents on tblstudents.StudentId=tblissuedbookdetails.StudentId join tblbooks on tblbooks.id=tblissuedbookdetails.BookId where tblissuedbookdetails.RetrunStatus is NULL and StudentId=:studentid order by tblissuedbookdetails.id desc";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
?>
<tr class="odd gradeX">
<td class="center"><?php echo htmlentities($cnt);?></td>
<td class="center"><?php echo htmlentities($result->FullName);?></td>
<td class="center"><?php echo htmlentities($result->BookName);?></td>
<td class="center"><?php echo htmlentities($result->ISBNNumber);?></td>
<td class="center"><?php echo htmlentities($result->IssuesDate);?></td>
<td class="center">
<?php if($result->RetrunStatus==NULL)
{
echo htmlentities("Not Returned Yet");
} else {
echo htmlentities("Returned");
}
?>
</td>
<td class="center">
</td>
</tr>
<?php $cnt=$cnt+1;}}} ?>
</tbody>
</table>
</div>
</div>
</div>
<!--End Advanced Tables -->
</div>
</div>
</div>
</div>
<!-- CONTENT-WRAPPER SECTION END-->
<?php include('includes/footer.php');?>
<!-- FOOTER SECTION END-->
<!-- JAVASCRIPT FILES PLACED AT THE BOTTOM TO REDUCE THE LOADING TIME -->
<!-- CORE JQUERY -->
<script src="assets/js/jquery-1.10.2.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="assets/js/bootstrap.js"></script>
<!-- DATATABLE SCRIPTS -->
<script src="assets/js/dataTables/jquery.dataTables.js"></script>
<script src="assets/js/dataTables/dataTables.bootstrap.js"></script>
<!-- CUSTOM SCRIPTS -->
<script src="assets/js/custom.js"></script>
Need to put studentid in input field value. So that when form submit, it posted and generate report. Update the following line and check.
<input class="form-control" type="text" name="studentid" id="studentid" autocomplete="off" required value="<?php echo strtoupper($_POST['studentid']); ?>" />
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Hi i am very new to PHP and Bootstrap. I developed a E-commerce website using php and Bootstrap.This application just adds and removes products to and fro into cart and also calculate the total price of all products and if a user have a coupon he can able to apply it 'off30' so,he will get a 30% discount on total price.I am going through error as Parse error: syntax error, unexpected end of file pointing the last line of below code. please help me to solve this error.
<?php
session_start();
error_reporting("E_ALL");
require_once("dbcontroller.php");
$conn = connectDB();
if(!empty($_GET["action"])) {
//echo $_GET["action"];
switch($_GET["action"]) {
case "add":
if(!empty($_POST["quantity"])) {
$productByCode = mysqli_query($conn,"SELECT * FROM tblproduct WHERE code='" . $_GET["code"] . "'");
$products = mysqli_fetch_array($productByCode);
$itemArray = array($products["code"]=>array('name'=>$products["name"], 'code'=>$products["code"], 'quantity'=>$_POST["quantity"], 'price'=>$products["price"]));
if(!empty($_SESSION["cart_item"])) {
if(in_array($products["code"],array_keys($_SESSION["cart_item"]))) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($products[0]["code"] == $k) {
if(empty($_SESSION["cart_item"][$k]["quantity"])) {
$_SESSION["cart_item"][$k]["quantity"] = 0;
}
$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
}
}
} else {
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
}
} else {
$_SESSION["cart_item"] = $itemArray;
}
}
break;
case "remove":
if(!empty($_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($_GET["code"] == $k)
unset($_SESSION["cart_item"][$k]);
if(empty($_SESSION["cart_item"]))
unset($_SESSION["cart_item"]);
}
}
break;
case "empty":
unset($_SESSION["cart_item"]);
break;
}
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$coupon = $_POST["coupon"];
$total = $_POST["total"];
if($coupon == "off30"){
$disc_item_total = $total*0.7;
}
else{
$disc_item_total = $total;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>All In One</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/business-casual.css" rel="stylesheet">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700,100italic,300italic,400italic,600italic,700italic" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="brand">All In One</div>
<!-- Navigation -->
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- navbar-brand is hidden on larger screens, but visible when the menu is collapsed -->
<a class="navbar-brand" href="index.html">Business Casual</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">
<li>
Home
</li>
<li>
About
</li>
<li>
Blog
</li>
<li>
<a id="btnEmpty" href="about.php?action=empty">Empty Cart</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<?php
if(isset($_SESSION["cart_item"])){
$item_total = 0;
?>
<div class="container">
<div class="row">
<div class="box">
<div class="col-lg-12">
<hr>
<h2 class="intro-text text-center">
<strong>Products</strong>in Cart
</h2>
<hr>
</div>
<div class="col-md-6">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Code</th>
<th>Quantity</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($_SESSION["cart_item"] as $item)
{
?>
<tr>
<td><strong><?php echo $item["name"]; ?></strong></td>
<td > <?php echo $item["code"]; ?></td>
<td > <?php echo $item["quantity"]; ?></td>
<td > <?php echo "Rs.".$item["price"]; ?></td>
<td > Remove Item</td>
</tr>
<?php
$item_total += ($item["price"]*$item["quantity"]);
}
?>
<tr>
<td colspan="3" align=right>Total:</td>
<td colspan="3"><b>Rs.=<?php $item_total;?></b></td>
</tr>
<tr>
<td colspan="3" align=right>Apply Coupon:</td>
<td>
<form action="" method="post">
<input type="text" id="coupon" name="coupon" value=""/>
<input type="hidden" name="total" value="<?php $item_total;?>">
</td>
<td>
<button type="submit" >Apply</button>
</form>
</td>
</tr>
<tr>
<td align=right colspan="3"> Discounted Amount:</td>
<td colspan="3"><b><?php "=Rs.".$disc_item_total; ?></b></td>
</tr>
</tbody>
<!--<?php echo $disc_item_total; ?>-->
</table>
<?php
}
?>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="row">
<div class="box">
<div class="col-lg-12">
<hr>
<h2 class="intro-text text-center">
<strong>Products</strong>
</h2>
<hr>
</div>
<?php
$product_array = mysqli_query($conn,"SELECT * FROM tblproduct ORDER BY id ASC");
//echo mysqli_num_rows($product_array);
if (!empty($product_array)) {
while($products = mysqli_fetch_array($product_array)){
?>
<div class="col-md-3 col-sm-6 hero-feature">
<div class="thumbnail">
<form method="post" action="about.php?action=add&code=<?php echo $products["code"]; ?>">
<div class="item active">
<img class="img-responsive img-full" src="img/a1.png" alt="">
</div>
<div class="caption">
<h4 class="pull-right"><?php echo "$".$products["price"]; ?></h4>
<h4><?php echo $products["name"]; ?></h4>
<div><input type="text" name="quantity" value="1" size="2" />
<p>
<input type="submit" value="Add to cart" class="btn btn-info" /></div>
</p>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<!-- /.container -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<p>Copyright © Your Website 2014</p>
</div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
The if(!empty($product_array)) and while($products = .....) loops are not closed. It might be a good idea to start indenting your code so that way you can see when something is off, it really help keep track of opening and closing tags.
I'm learning PHP from a book and I copied the code below from the book site. When I run it in Zend Studio and select any of the hyperlinks eg Home, all that's displayed is the name of the php file. For example index.php. It does not link to and execute the php file. Why is that?
Any help would be much appreciated, thank you.
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Class Registration Template</title>
<link rel= "stylesheet" type= "text/css" href= "C:\Users\trevor.reeves\Documents\PHP&mySQLBook\php-mysql-abg-listings-1\ClassRegistration_Public/registration.css"/>
<script type= "text/javascript"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<img src="C:\Users\trevor.reeves\Documents\PHP&mySQLBook\php-mysql-abg-listings-1\ClassRegistration_Public/MatTechLogo.gif" alt="Matthews Technology" />
<h1 id="title">Class Selection and Registration</h1>
</div> <!-- id="header" -->
<div id="hnav">
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><a class="hmenu" href="index.php">Home</a> </td>
<td>About </td>
<td>Support </td>
<td>Maintain </td>
</tr>
</table>
</div> <!-- id="hnav" -->
<div id="vnav">
<table width="120" border="0" cellspacing="2" cellpadding="2">
<tr>
<td id="vhead">Go To: </td>
</tr>
<tr>
<td>Class List </td>
</tr>
<tr>
<td>Student Entry
</td>
</tr>
</table>
</div> <!-- id="vnav" -->
<div id="main">
<h1 id="maintitle">Spring Class Schedule</h1>
<p id="mainpara">Click Register to do so for a class.</p>
<p class="red">*A footnote.</p>
</div> <!-- id="main" -->
<div id="footer">
<p id="copyright">
Copyright ©:2008 -
<?php
date_default_timezone_set('America/Vancouver');
echo date('Y');
?>
Matthews Technology
</p>
<p id="contact">
Contact us by clicking here.
</p>
</div> <!-- id="footer" -->
</div> <!-- id="wrapper" -->
<?php
;
?>
</body>
</html>
You are using the file reference your disk operating system using to access the files. You need to use the reference your server is using. Normally it would be localhost/directory/filename.php localhost will point to the location your server tells it to point to, which is located in you php.ini file.
This is my branch.php page and I want to delete and update row when the user click on the edit and delete image in php and directly the row should be deleted or updated in the table.But It is not working neither row is getting updated or deleted.
<?php
$a1=mysql_connect('localhost','root1','oec#123');
$b1=mysql_select_db('rms',$a1);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>branch</title>
<link href="styles/branch.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>Reporter Management System</h1>
<nav id="mainnav">
<ul>
<li>Home</li>
<li>Branch</li>
<li>Branch Admin</li>
<li>Reporters</li>
<li>Accountant</li>
<li>Settings</li>
<li>Log out</li>
</ul>
</nav>
</header>
<div id="hero">
<img src="News2.jpg" width="1000" height="320" alt=""/> </div>
<form role="form" action ="searchbranch.php" method="post">
<p><label for="Search">Search Branch :</label>
<input class="textbox" type="Search" placeholder="Name" name="Search">
<input type="submit" class="classname" value="Search" >
</form>
<form role= "form" action="createbranch.php" method="post">
<input type="submit" class="classname" value="Add Branch" onClick="href 'createbranch.php' " ></p>
</form>
<section class="page container">
<div>
<div class="span12">
<div class="box pattern ">
<div class="box-header">
<i class="icon-list"></i>
</div>
<table id="sample-table" class="table table-hover table-bordered tablesorter">
<thead>
<tr>
<th>Sl no</th>
<th>Branch</th>
<th>Description</th>
<th>Action</th>
</tr>
<?php
$w='SELECT Sl_no, branch, description from create_branch;';
$recordset=mysql_query($w,$a1) or die(mysql_error());
$totalrows=mysql_num_rows($recordset);
$row_recordset=mysql_fetch_assoc($recordset);
if($totalrows>0)
{
do
{
$r=$row_recordset['Sl_no'];
$d=$row_recordset['branch'];
$d1=$row_recordset['description'];
?>
</thead>
<tbody id='tb-content'>
<tr>
<td><?php echo $r ;?></td>
<td><?php echo $d ;?></td>
<td><?php echo $d1 ;?></td>
<td> <?php echo '
<a href="edit_branch.php?no='.$row_recordset['Sl_no'].'">'?>
<img src="pencil.png" />
<?php '</a>';? > | <?php echo'
<a href="branch_delete.php?no1='.$row_recordset['branch'].'">'?>
<img src="cross.png" /> <?php '</a>';?>
</td>
</tr>
<?php
}while($row_recordset=mysql_fetch_assoc($recordset));
}
mysql_free_result($recordset);
mysql_close($a1);
?>
</tbody>
</table>
</div>
</div>
</div>
</section>
</body>
<footer>
<p> </p><hr>
<center>©Copyright 2015 RepoterManagnmentSystem
</center>
</footer>
</div>
</body>
</html>
This is branch_delete.php
<?php
$cn=mysql_connect('localhost','root1',"oec#123");
$db_selected=mysql_select_db('rms',$cn);
$bn=$_REQUEST['no1'];
$sql='DELETE au.Sl_no,au.name,au.company_name,au.email_id,au.password,au.confirm_password,au.group,au.branch,au.phone,au.wordcount,au.rating,cb.Sl_no,cb.branch,cb.description from admin_user au,create_branch cb where cb.branch="'.$bn.'" AND au.branch=cb.branch ;';
$s1=mysql_query($sql,$cn);
mysql_close($cn);
header('Location: branch.php');
?>
This is update_branch.php
<?php
$a1=mysql_connect('localhost','root1','oec#123');
$b1=mysql_select_db('rms',$a1);
$bn=$_REQUEST['bname'];
$sn=$_REQUEST['Sl_no'];
$d=$_REQUEST['descp'];
$w= 'SELECT branch,description FROM create_branch;';
$recordset=mysql_query($w,$a1) or die(mysql_error());
$totalrows=mysql_num_rows($recordset);
$row_recordset=mysql_fetch_assoc($recordset);
if($totalrows>0)
{
do
{
$r=$row_recordset['branch'];
$s=$row_recordset['description'];
if($bn==$r and $d==$s)
{
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="styles/createbranch.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>Reporter Management System</h1>
<nav id="mainnav">
<ul>
<li>Home</li>
<li>Branch</li>
<li>Branch Admin</li>
<li>Reporters</li>
<li>Accountant</li>
<li>Settings</li>
<li>Log out</li>
</ul>
</nav>
</header>
<div id="hero">
<img src="News2.jpg" width="1000" height="320" alt=""/>
</div>
<form method="post" action="edit_branch.php">
<article id="main">
<?php echo '<h2>branch already exists</h2>' ; ?>
<h2>Create Branch</h2><hr>
<p><label for="branch name">Branch Name:</label><br><br>
<input class="textbox" type="text" placeholder=" <?php echo $bn ;?>" name="bname"></p><br>
<p><label for="Description">Description:</label><br><br>
<input class="textbox" type="text" placeholder="<?php echo $d ;?>" name="descp"></p><br>
<input type="submit" class="classname" value="Update Branch" ></p> <br>
</article>
</form>
<footer>
<p> </p><hr>
<center> © Copyright 2015 ReporterManagementSystem</center> </footer>
</div>
</body>
</html>
<?php
exit(0);
}
}
while($row_recordset=mysql_fetch_assoc($recordset));
$w1='UPDATE create_branch set branch="'.$bn.'" and description="'.$d.'" where Sl_no="'.$sn.'";';
$x=mysql_query($w1,$a1) or die(mysql_error());
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>Reporter Management System</h1>
<nav id="mainnav">
<ul>
<li>Home</li>
<li>Reporters</li>
<li>News Content</li>
<li>Add user</li>
<li>Log Out</li>
</ul>
</nav>
</header>
<img src="News2.jpg" width="1000" height="320" alt=""/>
<?php
echo "<br>";
if($x=="true")
{
header('Location: branch.php');
}
else
{
echo "fail to update branch";
}
echo"<br>";
}
mysql_free_result($recordset);
mysql_close($a1);
?>
The sql query incorrectly built.
To update an SQL query should look like this
UPDATE table_name SET
column1=value1,column2=value2,...
WHERE some_column=some_value;
Your update:
UPDATE create_branch SET
branch="'.$bn.'" ,
description="'.$d.'"
WHERE Sl_no="'.$sn.'"
Sql query - delete:
DELETE FROM table_name
WHERE some_column=some_value;
Your delete:
DELETE FROM create_branch
WHERE cb.branch="'.$bn.'"
Read MySQL documentation about FOREIGN KEY Constraints.
In the case of two tables joined the foreign key, delete or modify a record in the first result will be an appropriate operation on record in the second table.
Example:
MySQL Foreign Key On Delete