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.
Related
I have a implemented a shopping cart function on my project website by following this guide video on YT https://www.youtube.com/watch?v=eAK8uYtNTy4&t=3528s and I am able to add items to the shopping cart and remove items(kind of). However the remove function is very odd indeed,because it allows me to remove the item but when I clicked on it it also removes other items that is currently in the cart as well...
Here are my codes for the cart (cart.php)
<?php
session_start();
require_once ("conn.php");
require_once ("component.php");
if (isset($_POST['remove'])){
if ($_GET['action'] == 'remove'){
foreach ($_SESSION['cart'] as $key => $value){
if($value["ID"] == $_GET['game_ID']){
unset($_SESSION['cart'][$key]);
echo "<script>alert('Product has been Removed...!')</script>";
echo "<script>window.location = 'cart.php'</script>";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cart</title>
<link rel="icon" href= "images/logoonly.png" type="image/jpg" sizes="16x16">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/cart.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="js/sticky.js"></script>
<script src="https://kit.fontawesome.com/ac84272c35.js" crossorigin="anonymous"></script>
</head>
<body>
<!-- Navigation -->
<navbar>
<section class="navbar-section" style="background-color: #252525; box-shadow: 0px 2px 6px black;">
<div class="navbar-div">
<div class="navbar-div-logo">
<a href="index.html">
<img href="index.html" class="logo-pic" src="images/logoonly.png" alt="">
<img class="logo-name" src="images/logonameonly.png" alt="">
</a>
</div>
<ul class="navbar-ul-links">
<li> <a class="navbar-a-links" href="index.html">home</a> </li>
<li> <a class="navbar-a-links" href="store.php">store</a> </li>
<li> <a class="navbar-a-links" href="news.html">news</a> </li>
<li> <a class="navbar-a-links" href="about.html">about</a> </li>
</ul>
<div class="navbar-div-cart-login">
<i class="fas fa-shopping-bag"></i>
<a class="login navbar-a-links" href="login.html">login</a>
</div>
</div>
</section>
</navbar>
<!-- /Navigation -->
<!-- Main Content -->
<?php
$total = 0;
if (isset($_SESSION['cart'])){
$ID = array_column($_SESSION['cart'], 'game_ID');
include("conn.php");
$result = mysqli_query($con,"Select * from games where games.game_status = 1");
while($row = mysqli_fetch_array($result)){
foreach ($ID as $game_ID){
if ($row['game_ID'] == $game_ID){
cartElement( $row['game_name'],$row['game_price'], $row['game_ID']);
$total = $total + (int)$row['game_price'];
}
}
}
}else{
echo "<h5>Cart is Empty</h5>";
}
?>
</section>
<!-- /Main Content -->
<!-- Footer -->
<footer>
<section class="footer-section" style="background-color: black;">
</section>
</footer>
<!-- /Footer -->
<script src="js/modal.js"></script>
<!-- Animate Show Panel -->
<script type="text/javascript">
function show(elementId) {
document.getElementById("personal-info").style.display = "none";
document.getElementById("acc-info").style.display = "none";
document.getElementById(elementId).style.display = "flex";
}
</script>
<!-- /Animate Show Panel -->
</body>
</html>
here are the components for the cart to display the items. (component.php)
<?php
function component($game_name, $game_price, $game_ID){
$element = "
<form action=\"store.php\" method=\"post\">
<div class=\"newrelease\">
<div class=\"special-offer-description-div\">
<h5 name=\"game_name\">$game_name</input></h5>
<button type=\"submit\" class=\"purchase\" name=\"add\">Add To Cart</button>
<input type='hidden' name='game_ID' value='$game_ID'>
<div class=\"price-div\">
<h6>- 85%</h6>
<p class=\"strikethrough\" name=\"game_price\">RM$game_price</p>
</div>
</div>
</div>
</form>
";
echo $element;
}
function cartElement($game_name, $game_price, $game_ID){
$element = "
<form action=\"cart.php?action=remove&id=$game_ID\" method=\"post\">
<section class=\"cart-section\">
<div class=\"block\"></div>
<div class=\"cart-div\">
<h1>$game_name</h1>
<!-- Cart Games -->
<div class=\"cart-items-div\">
<div class=\"description-div\">
<div class=\"description\">
<!-- Game Name -->
<h2 class=\"game-title\"></h2>
<!-- Game Description -->
<div class=\"d\">
<div class=\"details\">
<h2>overall reviews:</h2>
<h2>release date:</h2>
</div>
<div class=\"game-details\">
<h2 style=\"color: #407AD3;\">very positive</h2>
<h2>8 aug, 2018</h2>
</div>
</div>
<!-- Game Specification -->
<div class=\"compatibility\">
<i class=\"fab fa-windows\"></i>
<i class=\"fab fa-apple\"></i>
<i class=\"fab fa-linux\"></i>
</div>
</div>
<div class=\"button-div\">
<!-- Remove Game From Cart Button -->
<button type=\"submit\" class=\"btn btn-danger mx-2\" name=\"remove\"><i class=\"fas fa-trash-alt\" style=\"color: #FF4444\" ></i> </button>
<!-- Purchase Game -->
<button class=\"purchase\" input type=\"text\" value=\"1\">Purchase</button>
<!-- Price -->
<h3 style=\"border-right: none;\">$game_price</h3>
</div>
</div>
</div>
</form>
";
echo $element;
}
I am trying to implement the bootstrap datetimepicker and am running into an issue where clicking on the input box doesn't trigger any action. I have double checked my imports along with the code itself following several tutorials, but I am not able to find the issue with my code. The imports I am using are as followed:
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="js/bootstrap-datetimepicker.min.js"></script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
I have downloaded the datetimepicker repo and have selected the css and js folder and moved them to the main directory.
The code I am calling for the label is as follows:
<div class="row">
<div class='col-sm-6'>
<input size="16" type="text" class="form-control" id="datetime" readonly>
<script type="text/javascript">
$("#datetime").datetimepicker({
format: 'yyyy-mm-dd hh:ii'
});
</script>
</div>
</div>
As I have stated the label doesn't have any action when clicked on. I am not sure if you need the whole webpage to understand my issue but I will post it below:
<?php
require('./includes/connection.php');
require('./includes/crypt.php');
require('functions.php');
session_start();
ob_start();
/**
* Created by PhpStorm.
* User: peri
* Date: 2019-04-07
* Time: 16:48
*/
if(isset($_GET['cancel'])) {
header('Location: messaging.php');
exit();
}
if(isset($_GET['confirm'])) {
if(isset($_GET['reason'])) {
//Encrypted text
$encrypted_text = encrypt_text($_GET['reason'], $key, $iv);
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="js/bootstrap-datetimepicker.min.js"></script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<title>New Appointment</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark align-center">
<a class="navbar-brand" href="#">EMR System</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse align-center" id="navbarNav">
<ul class="navbar-nav align-center">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Appointment <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Prescription</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Lab Tests</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Billing</a>
</li>
</ul>
</div>
<div class="navbar-collapse collapse order-3 dual-collapse2">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<img src="https://png.pngtree.com/element_our/sm/20180620/sm_5b29c1b6c8772.png" width="45px" height="45px">
</li>
</ul>
</div>
</nav>
<br>
<div class="container h-100">
<div class="row align-items-center h-100">
<div class="col-5 mx-auto">
<div class="card h-100 border-primary justify-content-center">
<div>
<?php
//Running query to fetch physician details
$row = get_physician_information_messaging($_SESSION['phy_ssn']);
//echo var_dump($row);
//$message = "test";
//insert_message($_SESSION['ssn'], $message, 0);
?>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col" colspan="6">Physician Information</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">First Name:</th>
<td class="col-md-6"> <?php echo $row[0]?></td>
<th scope="row">Last Name:</th>
<td class="col-md-6"> <?php echo 'Dr. ' . $row[2]?></td>
</tr>
<tr>
<th scope="row">Phone Number:</th>
<td class="col-md-6"><?php echo $row[3] ?></td>
<th scope="row">Speciality:</th>
<td class="col-md-6"><?php echo $row[4] ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="container h-100">
<div class="row align-items-center h-100">
<div class="col-12 mx-auto">
<div class="card h-100 border-primary justify-content-center">
<div>
<form method="get" action="new_appointment.php">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col" colspan="2">Reason for visit</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="form-group">
<label for="visit_reason">Enter your reason for the visit. Be as descriptive as possible.</label>
<textarea class="form-control" id="visit_reason" rows="3" name="reason"></textarea>
</div>
</td>
</tr>
<tr>
<td>
<div class="container">
<div class="row">
<div class='col-sm-6'>
<input size="16" type="text" class="form-control" id="datetime" readonly>
<script type="text/javascript">
$("#datetime").datetimepicker({
format: 'yyyy-mm-dd hh:ii'
});
</script>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td class="text-center">
<button type="submit" class="btn btn-success" name="confirm">Confirm</button>
<button type="submit" class="btn btn-danger" name="cancel">Cancel</button>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Could someone point out my issue? (Note: All of the code I have used for the datetimepicker were copied pasted from tutorials which is another reason as to why I am puzzled.)
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:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
So this is for a school project. We are making a website and I am using PHP with MySQL and phpMyAdmin.
My problem is that when I am updating a product instead of changing the field, it erases all the data for the row besides the ProductID, which is the primary key.
***EDIT: I will address this here: This is a school project and thus security is not an issue for me.
I just need the products to update, now. The erasing problem has been solved.
** End Edit **
Code:
update-page.php - has the actual form in it
<'?'php
session_start();
require_once 'db_connect.php';
$query = "SELECT * FROM Products";
$result = mysql_query($query);
if (!$result) {
die("Database query failed: " . mysql_error());
}
$num = mysql_num_rows($result);
?>
<!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>AppleRetail - Update Product</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/update-custom.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" 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>
<a class="navbar-brand" href="index.html">AppleRetail.com</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>
Products
</li>
<li>
Add Product
</li>
<li>
Delete Product
</li>
<li>
Update Price
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<!-- Jumbotron Header -->
<header class="jumbotron hero-spacer">
<h1>Update Product</h1>
<p>Change the information below and select "Update" to update the product information.</p>
</header>
<hr>
<form action="update.php" method="POST">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Product ID</th>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Image URL</th>
</tr>
</thead>
<tbody>
<?php while($row = mysql_fetch_array($result)) { ?>
<tr>
<input type="hidden" name="id" value="<?php echo $row['ProductID']; ?>"/>
<td><?php echo $row['ProductID']; ?></td>
<td><input type="text" name="name" value="<?php echo $row['Name']; ?>"/></td>
<td><input type="text" name="description" value="<?php echo $row['Description']; ?>"/></td>
<td><input type="text" name="price" value="<?php echo $row['Price']; ?>"/></td>
<td><input type="text" name="image" value="<?php echo $row['Image']; ?>"/></td>
<td>
<input type="submit" name="update" value="Update">
</td>
</tr>
<?php }?>
</tbody>
</table>
</form>
<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright © AppleRetail.com</p>
</div>
</div>
</footer>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
And then the update.php has the query in it.
<?php
session_start();
require_once 'db_connect.php';
// Grab the posted data and send to variable
$ProductID = $_POST['ProductID'];
$Name = $_POST['Name'];
$Description = $_POST['Description'];
$Price = $_POST['Price'];
$Image = $_POST['Image'];
$_SESSION['ProductId1'] =$ProductId;
$_SESSION['Name1'] = $Name;
$_SESSION['Description1'] = $Description;
$_SESSION['Price1'] = $Price;
$_SESSION['Image1'] = $Image;
$query = "UPDATE Products SET Name='$Name', Description='$Description', Price='$Price', Image='$Image' WHERE ProductID='$ProductID'";
$result = mysql_query($query);
if (!$result) {
die("Database query failed: " . mysql_error());
}
if($result =='true'){echo "<p>Post is add</p>";}
else{ echo "<p>Post is not add</p>"; }
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>AppleRetail Update Page</title>
</head>
<body>
<?php header("Location: updateFinal.php"); ?>
</body>
</html>
Any Help is appreciated! Thank you!
Please ask if more information is needed!
input type="text" name="name"
input type="text" name="description"
Compare that with
$_POST['Name'];
^
$_POST['Description'];
^
And spot the error ;)
I need to build progress bar next to the names of people showing how many costumers each people have working for him. When you see the code you will understand my problem. I dont know how to build this.
Just before end of body, before script tags i have progress bar and var that show's names from db. I need to show that names and beside them progress bar with percentage of costumers.
this are my tables
<?php
if (isset($_GET['poslovni_korisnici'])) {
$active1 = 'class="active"';
}
else {
$active1 = '';
}
if(isset($_GET['korisnici'])) {
$active2 = 'class="active"';
}
else {
$active2 = '';
}
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'root';
/*** mysql password ***/
$password = '';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=zadatak1", $username, $password);
/*** echo a message saying we have connected ***/
/**echo 'Connected to database';**/
}
catch(PDOException $e)
{
echo $e->getMessage();
}
echo'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Statistika</title>
<!-- Bootstrap -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- 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">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">POSLOVNA STATISTIKA</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 ' . $active1 . '>Poslovni korisnici <span class="sr-only">(current)</span></li>
<li ' . $active2 . '>Korisnici</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>';
switch (isset($_GET)) {
case isset($_GET['poslovni_korisnici']):
echo'
<h1>Poslovni korisnici</h1>
<button type="button" class="btn btn-default btn-sm">Unos</button>
</br>
</br>';
echo'
<table id="table_id" class="display">
<thead>
<tr>
<th>Partner id</th>
<th>Partner name</th>
<th>Partner street</th>
<th>Partner zip</th>
<th>Partner city</th>
<th>Partner country</th>
</tr>
</thead>
<tbody>';
$sql = "SELECT * FROM poslovni_partneri";
foreach ($dbh->query($sql) as $row)
{
echo'
<tr>
<td>'.$row['Partner_id'].'</td>
<td>'.$row['Partner_name'].'</td>
<td>'.$row['Partner_street'].'</td>
<td>'.$row['Partner_zip'].'</td>
<td>'.$row['Partner_city'].'</td>
<td>'.$row['Partner_country'].'</td>
</tr>';
}
echo'
</tbody>
</table>';
break;
case (isset($_GET['korisnici'])):
echo'
<h1>Korisnici</h1>
<button type="button" class="btn btn-default btn-sm">Unos</button>
</br>
</br>
<table id="table_id" class="display">
<thead>
<tr>
<th>User id</th>
<th>Partner ID</th>
<th>User name</th>
<th>User department</th>
<th>User email</th>
<th>User phone</th>
<th>User mobile</th>
</tr>
</thead>
<tbody>';
$sql = "SELECT * FROM korisnici
INNER JOIN poslovni_partneri
ON korisnici.Partner_id=poslovni_partneri.Partner_id";
foreach ($dbh->query($sql) as $row)
{
echo'
<tr>
<td>'.$row['User_id'].'</td>
<td>'.$row['Partner_id'].'</td>
<td>'.$row['User_name'].'</td>
<td>'.$row['User_department'].'</td>
<td>'.$row['User_email'].'</td>
<td>'.$row['User_phone'].'</td>
<td>'.$row['User_mobile'].'</td>
</tr>';
}
echo'
</tbody>
</table>';
break;
default:
$sql = "SELECT Partner_name FROM poslovni_partneri";
$del = $dbh->prepare('SELECT * FROM poslovni_partneri');
$del->execute();
$count = $del->rowCount();
$del = $dbh->prepare('SELECT * FROM korisnici');
$del->execute();
$count2 = $del->rowCount();
echo '<div class="panel panel-primary">
<div class="panel-heading">Popis poslovnih partnera</div>
<div class="panel-body">
<button class="btn btn-primary" type="button">
Broj poslovnih korisnika <span class="badge">'.$count.'</span>
</button>
</br>
</br>
<button class="btn btn-primary" type="button">
Broj korisnika <span class="badge">'.$count2.'</span>
</button>
</br>
</br>
<div class="panel panel-primary">
<div class="panel-heading">Popis poslovnih partnera <p class="text-center">Ukupni udio</p></div>
<ul class="list-group">';
foreach ($dbh->query($sql) as $row)
{
echo'
<li class="list-group-item list-group-item-info">
<span class="badge">144</span>
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:%">
<span class="sr-only">40% Complete (success)</span>
</div>
</div>
<h4 class="names">'.$row['Partner_name'].'</h4>
</li>';
}
echo'
</ul>
</div>
</div>';
break;
}
echo'
<script>
$(document).ready( function () {
$("#table_id").DataTable();
} );
</script>
<!-- jQuery (necessary for Bootstraps JavaScript plugins) -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>';
?>
You should first get count of customers of each people. Now on basis of number of customers build your progress bar.
Step 1.
Get count of customers.
//add your logic here
$customer_count=<for_exampe_its_20>
Step 2.
Now on basis of count display your progress bar
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<? php echo ($customer_count) ?>" aria-valuemin="0" aria-valuemax="100" style="width: <? php echo ($customer_count) ?>%">
<span class="sr-only"><? php echo ($customer_count) ?>customers(success)</span>
</div>
</div>