My page refreshes when I click on a button - php

I have products page and each product has add to cart and more description button. more description is supposed to display extra description of the product ONLY. However, when it is clicked, it displays the extra description for a second and the page refreshes. I am focusing on the button only, so php can be ignored (unless it is the issue)
Here is the code for one of the products:
<?php
if (isset($_POST['insert']))
{
$xml = new DomDocument("1.0", "UTF-8");
$xml->load('products.xml');
$pimage = 'Images/zucchini.jpg';
$pname = 'Zucchini';
$pquantity = $_POST['p-quantity'];
$pprice = 1.76;
$rootTag = $xml->getElementsByTagName("root")->item(0);
$infoTag = $xml->createElement("info");
$imgTag = $xml->createElement("img", $pimage);
$nameTag = $xml->createElement("name", $pname);
$priceTag = $xml->createElement("price", $pprice);
$quantityTag = $xml->createElement("quantity", $pquantity);
$infoTag->appendChild($imgTag);
$infoTag->appendChild($nameTag);
$infoTag->appendChild($priceTag);
$infoTag->appendChild($quantityTag);
$rootTag->appendChild($infoTag);
$xml->save('products.xml');
}
?>
<!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.0">
<title>Document</title>
<link rel="stylesheet" href="../css/bootstrap-grid.css">
<link rel="stylesheet" href="../css/bootstrap.css">
<link rel="stylesheet" href="../Main-Stylesheet.css">
<link rel="stylesheet" type="text/css" href="../AislesDesign.css">
<link rel="stylesheet" type="text/css" href="ProductPages.css">
<script src="../Refresh.js" async></script>
<script src="../productPages.js" async></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
#more {display: none;}
</style>
</head>
<body>
<!-- header section -->
<nav class="nav_bar">
<a class="nav_logo" href="../index.php">
<img src="../Images/Logo.png">
</a>
<form class="search">
<input class="search_bar" type="search" placeholder="'Product'">
<button class="search_button" type="submit">Search</button>
</form>
<a class="cart_button" href="../ShoppingCart.php">
<div class="cart_circle">
<img src="../Images/cart-logo.png" />
</div>
</a>
</nav>
<div class="row menu h-100 col-12 nopadding sticky-top">
<div class="col-4 row text-center">
<div class="dropdown menuText">
<button class="dropbtn"><img class="dropdown-hamburger"src="../Images/hamburger-icon2.jpg" /><p class="nav-aisles">Aisles</p></button>
<div class="col-3 row dropdown-content">
Chicken
Meat
Pasta
Fruits
Vegetables
</div>
</div>
</div>
<div class="col-4 row menuText h-100">
Home
</div>
<div class="col-4 row menuText h-100">
<a>Locations</a>
</div>
</div>
<form method = "POST" action = "zucchiniProduct.php">
<div class="product-border">
<img class="images" name = "p-img" src="../Images/zucchini.jpg"
alt="Image of zucchini">
<div class="display">
<h3 class="product-name-zucchini" name = "p-name">Zucchini</h3>
<div class="moredescription_contain">
<p class="product-description">1 vegetable (approx. 320g)<span id="dots">...</span><span id="more">. Zucchini is a favourite vegetable for many people as it can be used in variety of dishes, especially during summer. It is very rich in vitamin C, folate and antioxidants and low in calories.</span></p>
</div>
<span class="product-price" name = "p-price"> $1.76</span>
<p class="product-quantity"> Quantity:
<input class="product-quantity-input" type="number" value="1" step="1" name = "p-quantity"></input>
</p>
<input type = "submit" name = "insert" value = "Add to Cart" class="button"></input>
</form>
<button onclick="clickDesc()" id="myBtn" class="button">More Description</button>
</div>
</div>
<script>
function clickDesc() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "More Description";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
</script>
<div class="col-12 row h-100 nopadding footer">
<div class="col-4 row footer-heading nopadding about">
<h2>About Us</h2>
Our Story
Blog
Customers
</div>
<div class="col-4 row footer-heading nopadding contact-form">
<h2>Customer Service</h2>
Contact Us
Terms and Conditions
Find a Store
FAQ
</div>
<div class="col-4 row footer-heading nopadding social-media">
<h2>Social Media</h2>
Instagram
Facebook
YouTube
Twitter
</div>
<div class="col-12 row nopadding">
<div class="col-2 footer-bottom footer">
© 2022 poeatry.com
</div>
<div class="col-5">
</div>
</div>
</div>
<!-- footer section -->
</body>
</html>

The issue is that you opened this div <div class="product-border"> and this div <div class="display"> inside the form tag and then you closed it outside the form tag, which was causing the issue. To fix this issue close these divs properly inside the form tag.
Here's the link to the fixed version of your code.

Related

Removing one item from cart removes everything instead

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;
}

PHP HTTP Header appears multiple times with the same message

I have a page named as add_administrator.php in this php i am checking if the status value is given using the GET method and if so that display the header with the value in status Now i am getting the value form a page add_administrator_code.php But the problem is that i am getting the header more then once i.e. Three times with the same message What should i do?
here is the add_administrator.php
<?php
session_start();
session_regenerate_id(true);//regenerating session id on every reload or refresh so to avoid the session hijack
if (isset($_GET['status'])) {
$sta = $_GET['status'];
echo "<script type='text/javascript'>alert('$sta');</script>";
}
if($_SESSION['alogin'])
{
}
else
{
header("location:../index.php");
}
?>
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Smart Ambulance</title>
<link rel="stylesheet" href="assets/css/normalize.css">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/themify-icons.css">
<link rel="stylesheet" href="assets/css/flag-icon.min.css">
<link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
<!-- <link rel="stylesheet" href="assets/css/bootstrap-select.less"> -->
<link rel="stylesheet" href="assets/scss/style.css">
<link href="assets/css/lib/vector-map/jqvmap.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
<!-- Fav and touch icons -->
<?php include 'logo.php';?>
</head>
<body>
<!-- Left Panel -->
<aside id="left-panel" class="left-panel"style="background-color:#004466">
<nav class="navbar navbar-expand-sm navbar-default">
<?php include 'left_menu.php';?>
</nav>
</aside><!-- /#left-panel -->
<!-- Left Panel -->
<!-- Right Panel -->
<div id="right-panel" class="right-panel">
<!-- Header-->
<header id="header" class="header">
<?php include 'header_menu.php';?>
</header><!-- /header -->
<!-- Header-->
<div class="breadcrumbs">
<div class="col-sm-4">
<div class="page-header float-left">
<div class="page-title">
<h1>Dashboard</h1>
</div>
</div>
</div>
<div class="col-sm-8">
<div class="page-header float-right">
<div class="page-title">
<ol class="breadcrumb text-right">
<li class="active">Dashboard / User Details / Adminsitrator / Add</li>
</ol>
</div>
</div>
</div>
</div>
<div class="content mt-3">
<!--********************************************** Content Start **********************************************-->
<div class="col-lg-6">
<div class="card">
<div class="card-header">
<strong>Add Adminsitrator</strong>
</div>
<div class="card-body card-block">
<form action="add_administrator_code.php" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="row form-group">
<!--<div class="col col-md-3"><label class=" form-control-label">Static</label></div> -->
<div class="col-12 col-md-9">
<!-- <p class="form-control-static">Username</p> -->
</div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="text-input" class=" form-control-label">Name</label></div>
<div class="col-12 col-md-9"><input type="text" id="adm_name" name="adm_name" placeholder="Name" class="form-control"><small class="form-text text-muted"></small></div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="email-input" class=" form-control-label">Contact Number</label></div>
<div class="col-12 col-md-9"><input type="text" id="adm_mob" name="adm_mob" placeholder="Enter Contact Number" class="form-control"><small class="help-block form-text"></small></div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="email-input" class=" form-control-label">Email Id</label></div>
<div class="col-12 col-md-9"><input type="email" id="adm_mail_id" name="adm_mail_id" placeholder="Enter Email" class="form-control"><small class="help-block form-text"></small></div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="password-input" class=" form-control-label">Password</label></div>
<div class="col-12 col-md-9"><input type="password" id="adm_pass" name="adm_pass" placeholder="Password" class="form-control"><small class="help-block form-text">Press the Generate Button to generate password</small></div>
</div>
<div class="row form-group">
<div align =center class="col col-md-1"><input type="checkbox" onclick="togglepassword()" ></div>
<label for="text-input" class=" form-control-label">Show Password</label>
</div>
<div>
<button type="submit" class="btn btn-primary btn-sm">
<i class="fa fa-dot-circle-o"></i> Submit
</button>
<button type="reset" class="btn btn-danger btn-sm">
<i class="fa fa-ban"></i> Reset</i>
</button>
<button type="button" onclick="generate()" class="btn btn-success btn-sm">Generate</button>
</div>
</div>
<!--********************************************** Content End **********************************************-->
</div>
</div><!-- /#right-panel -->
<!-- Right Panel -->
<script src="assets/js/vendor/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="assets/js/plugins.js"></script>
<script src="assets/js/main.js"></script>
<script src="assets/js/lib/chart-js/Chart.bundle.js"></script>
<script src="assets/js/dashboard.js"></script>
<script src="assets/js/widgets.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.min.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.sampledata.js"></script>
<script src="assets/js/lib/vector-map/country/jquery.vmap.world.js"></script>
<script>
( function ( $ ) {
"use strict";
jQuery( '#vmap' ).vectorMap( {
map: 'world_en',
backgroundColor: null,
color: '#ffffff',
hoverOpacity: 0.7,
selectedColor: '#1de9b6',
enableZoom: true,
showTooltip: true,
values: sample_data,
scaleColors: [ '#1de9b6', '#03a9f5' ],
normalizeFunction: 'polynomial'
} );
} )( jQuery );
</script>
<script>
function togglepassword() {
var x = document.getElementById("adm_pass");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
<script>
function generate(){
//set password length/complexity
let complexity = 8;
//possible password values
let values = "ABCDEFGHIJKLMNOPQRSTUVWZYZabcdefghijklmnopqrstuvwxyz1234567890!##$%^&*()_+";
let password = "";
//create for loop to choose password characters
for(var i = 0; i <= complexity; i++){
password = password + values.charAt(Math.floor(Math.random() * Math.floor(values.length - 1)));
}
//add password to textbox/display area
document.getElementById("adm_pass").value = password;
}
</script>
</body>
</html>
here is the add_administrator_code.php
<?php include '../database.php';
// create a variable
$adm_name=$_POST['adm_name'];
$adm_mob=$_POST['adm_mob'];
$adm_mail_id=$_POST['adm_mail_id'];
$adm_pass=$_POST['adm_pass'];
mysqli_query($con,"INSERT INTO admin_details (adm_name,adm_mob,adm_mail_id,adm_pass)
VALUES ('$adm_name','$adm_mob','$adm_mail_id','$adm_pass')");
if(mysqli_affected_rows($con) > 0){
$status = "New Admin added Sucessfully";
header("location: add_administrator.php?status=".$status);
} else {
$status = "Error in adding New Admin";
header("location: add_administrator.php?status=".$status);
}
?>
You need to stop the script after you redirect to make sure nothing else runs:
{
header("location: ...");
exit;
}
Also, your code is vulnerable to both XSS and SQL injection. Read about escaping HTML and prepared statements.
for preventing loop the session start: instead of
session_start();
session_regenerate_id(TRUE);
change to this:
if (session_status() == PHP_SESSION_NONE) {
session_start();
session_regenerate_id(TRUE);
}
update me with the result,
Note: dont forget to normalize the $_GET method for the security
improvement

How to resolve end of file error in php code?

I am new to php. I have a sign up page that takes in few user details and makes an account. On running the code I get this error:
Parse error: syntax error, unexpected end of file on line 347
I have seen few other posts related to the same issue but I didnt find any of those helpful for my code. I have reviewed the code many times to see what I have done wrong but couldn't find my mistake. Please help with the statement or point where I have gone wrong. Thanks in advance.
My code is below:
sign-up.php
<!DOCTYPE html>
<html>
<head>
<title>My Trip Planner | Sign Up </title>
<!-- for-mobile-apps -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Xtreme Travel Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- //for-mobile-apps -->
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/styles.css?v=1.6" rel="stylesheet">
<!-- js -->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/scripts.js?v=1.7"></script>
<!-- //js -->
<!-- start-smoth-scrolling -->
<script type="text/javascript" src="js/move-top.js"></script>
<script type="text/javascript" src="js/easing.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
});
});
</script>
<script type="text/javascript">
function formValidation()
{
var uid = document.registration.userid;
var passid = document.registration.passid;
var uemail = document.registration.email;
if(userid_validation(uid,5,12))
{
if(passid_validation(passid,7,12))
{
if(ValidateEmail(uemail))
{
}
}
}
return false;
}
function userid_validation(uid,mx,my)
{
var uid_len = uid.value.length;
if (uid_len == 0 || uid_len >= my || uid_len < mx)
{
alert("User Id should not be empty / length be between "+mx+" to "+my);
uid.focus();
return false;
}
return true;
}
function passid_validation(passid,mx,my)
{
var passid_len = passid.value.length;
if (passid_len == 0 ||passid_len >= my || passid_len < mx)
{
alert("Password should not be empty / length be between "+mx+" to "+my);
passid.focus();
return false;
}
return true;
}
function ValidateEmail(uemail)
{
var mailformat = /^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(uemail.value.match(mailformat))
{
//alert("You have entered a valid email address!");
return true;
}
else
{
alert("You have entered an invalid email address!");
uemail.focus();
return false;
}
}
</script>
<!-- start-smoth-scrolling -->
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Comfortaa:400,300,700' rel='stylesheet' type='text/css'>
</head>
<?php
session_start();
if(!empty($_POST)) {
class MyDB extends SQLite3
{
function __construct()
{
$this->open('mytrip.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
}
$id=null;
$pass=null;
$email=null;
$fname=null;
$lname=null;
$id_exists=false;
if (isset($_POST['uid'])) {
$id = $_POST['uid'];
}
if (isset($_POST['passid'])) {
$pass = $_POST['passid'];
}
if (isset($_POST['uemail'])) {
$email = $_POST['uemail'];
}
if (isset($_POST['first'])) {
$fname = $_POST['first'];
}
if (isset($_POST['last'])) {
$lname = $_POST['last'];
$result= "SELECT COUNT(*) FROM Users WHERE ID = '".$id. "';" ;
$count= $db->querySingle($result);
if ($count > 0)
{
$id_exists = true;
echo "This id is not available. Please enter a valid id. ";
}
else
{
$sql= " INSERT INTO Users (ID, PASSWORD, EMAIL, FNAME, LNAME)
VALUES ('$id','$pass','$email', '$fname', '$lname'); " ;
$ret = $db->query($sql);
$_SESSION['Id'] = $id;
header("location:index.php");
}
$db->close();
}
?>
<body>
<!-- banner -->
<div class="banner1">
<div class="navigation">
<div class="container-fluid">
<nav class="pull">
<ul class="nav">
<li> Home</li>
<li> About</li>
<li>Popular Places<span class="glyphicon glyphicon-menu-down" aria-hidden="true"></span></li>
<ul class="nav-sub">
<li>Place 1</li>
<li>Place 2</li>
<li>Place 3</li>
</ul>
<script>
$( "li a.menu" ).click(function() {
$( "ul.nav-sub" ).slideToggle( 300, function() {
// Animation complete.
});
});
</script>
<li> Events</li>
<li> Mail us</li>
</ul>
</nav>
</div>
</div>
<div class="header-top">
<div class="container">
<div class="head-logo">
<span>M</span>y Trip Planner<i>Feeling Amazing Tour</i>
</div>
<div class="top-nav">
<div class="hero fa-navicon fa-2x nav_slide_button" id="hero">
<img src="images/menu.png" alt="">
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
<!-- banner -->
<!-- sign-in -->
<div class="sign-in">
<div class="container">
<div class="in-form">
<h3>Register Here</h3>
<p class="use">Having hands on experience in creating innovative
designs,I do offer design solutions which harness.</p>
<div class="sign-in-form">
<div class="in-form Personal">
<h4>Personal Information</h4>
<form method="post" name='registration' onSubmit="return formValidation();">
<input type="text" placeholder="Firstname*" required=" " name="first">
<input type="text" placeholder="Lastname*" required=" " name="last">
<input type="text" placeholder="Emailaddress*" required=" " name="uemail">
<h4 class="kij">Login Information</h4>
<input type="text" placeholder="Id*" required=" " name="uid">
<input type="password" placeholder="Password*" required=" " name="passid">
<input type="password" placeholder="Confirm Password*" required=" ">
<input type="submit" value="submit">
</form>
</div>
</div>
</div>
</div>
</div>
<!-- //sign-in -->
<!-- footer-top -->
<div class="footer-top">
<div class="container">
<div class="col-md-3 footer-top-grid">
<h3>About <span> My Trip Planner</span></h3>
<p>Lets you plan the finest trips.</p>
</div>
<div class="col-md-3 footer-top-grid">
<h3>THE <span>TAGS</span></h3>
<div class="unorder">
<ul class="tag2">
<li>pool</li>
<li>gym</li>
<li>beach</li>
</ul>
<ul class="tag2">
<li>asian</li>
<li>thai</li>
<li>chinese</li>
<li>american</li>
</ul>
<ul class="tag2">
<li>theme park</li>
<li>wildlife</li>
<li>heritage</li>
</ul>
<ul class="tag2">
<li>shopping malls</li>
<li>local shops</li>
<li>boutiques</li>
</ul>
</div>
</div>
<div class="col-md-3 footer-top-grid">
<h3> User <span> Reviews</span></h3>
<ul class="twi">
<li>Location is close to empire state building and near bus stop. Staff was pleasant on check in.
<span></span></li>
<li>Outstanding food and service. Would return without hesitation.
<span></span></li>
<li>My wife and I love walking around and exploring cities. and New York is one of the few cities in USA you can enjoy doing that. SoHo has a great vibe about it, and we enjoyed walking around, grabbing a quick bite, and doing some shopping.
<span></span></li>
</ul>
</div>
<div class="col-md-3 footer-top-grid">
<h3> Popular <span> Destinations</span></h3>
<div class="flickr-grids">
<div class="flickr-grid">
<img src="images/minar.jpg" alt=" " class="img-responsive" />
</div>
<div class="flickr-grid">
<img src="images/bad.jpg" alt=" " class="img-responsive" />
</div>
<div class="flickr-grid">
<img src="images/kua1.jpg" alt=" " class="img-responsive" />
</div>
<div class="clearfix"> </div>
<div class="flickr-grid">
<img src="images/kua.jpg" alt=" " class="img-responsive" />
</div>
<div class="flickr-grid">
<img src="images/newyork.jpg" alt=" " class="img-responsive" />
</div>
<div class="flickr-grid">
<img src="images/can1.jpg" alt=" " class="img-responsive" />
</div>
<div class="clearfix"> </div>
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
<!-- //footer-top -->
<!-- footer -->
<div class="footer">
<div class="container">
<div class="footer-left">
<ul>
<li><i>M</i>y Trip Planner<span> |</span></li>
<!-- <li><p>The awesome agency. <span>0800 (123) 4567 // Australia 746 PO</span></p></li> -->
</ul>
</div>
<div class="footer-right">
<p>© 2017 My Trip Planner. All rights reserved | </p>
</div>
<div class="clearfix"> </div>
</div>
</div>
<!-- //footer -->
<!-- here stars scrolling icon -->
<script type="text/javascript">
$(document).ready(function() {
/*
var defaults = {
containerID: 'toTop', // fading element id
containerHoverID: 'toTopHover', // fading element hover id
scrollSpeed: 1200,
easingType: 'linear'
};
*/
$().UItoTop({ easingType: 'easeOutQuart' });
});
</script>
<!-- //here ends scrolling icon -->
</body>
</html>
you have this error because you miss "}" at line 141:
if (isset($_POST['last'])) {
$lname = $_POST['last'];
Add a closing bracket to line 141, so that the code is:
if (isset($_POST['last'])) {
$lname = $_POST['last'];
}
I tested your code locally and this is what fixed the syntax error.
What IDE or text editor do you use to write your code? I would suggest you something what points out such simple mistakes. For example netbeans for php or php storm, netbeans is free, php storm is not. Both of these editors will show to you your mistakes like this.

how to show jquery rating in html <list> tag in while loop using multiple tables

i want to show rating of each item or name of company with company name (driven from another table in database) in "li" tag of html (transporters.php). I have got the rating for each company page individually (transporters2.php) but i want to get all the ratings of all the companies or items in "li" tab so user can overview it and after clicking an "li" item it will show the profile of company "transporters2.php". Here are my two files transporters.php and transporters2.php and also their snapshots.
transporters.php and transporters2.php ,Mydatabase
Note: Both files are working correctly there is no syntax error, if an error occurs that might be occurred while posting the question thanks.
Transporters.php
<?php
include "header.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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="">
<script src="../js/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="../css/rating.css" />
<script type="text/javascript" src="../js/rating.js"></script><title>Transporters</title>
<!-- Bootstrap Core CSS -->
<link href="file:///C|/xampp/htdocs/bin/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="file:///C|/xampp/htdocs/bin/css/modern-business.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="file:///C|/xampp/htdocs/bin/font-awesome/css/font
awesome.min.css" 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]-->
<link href="../css/example.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
</head>
<body>
<!-- Page Content -->
<div class="container">
<!-- Page Heading/Breadcrumbs -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Transporters
<small> Companies</small>
</h1>
<ol class="breadcrumb">
<li>Home
</li>
<li class="active">Transporters</li>
</ol>
</div>
</div>
<!-- /.row -->
<!-- Content Row -->
<div class="row">
<div class="col-lg-12"><?php
require("Config.php");
$sql =mysql_query("SELECT * FROM transporters");
?>
<ul style="list-style:none;">
<?php while($row=mysql_fetch_array($sql) )
{
$cid=$row['CompanyID'];
?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<li><div class="product" style="font: 10px verdana, sans-serif;margin: 0 auto 40px auto;width: 71px;height: 4px;margin-right: 75%;">
<div id="<?php echo $cid ?>" class="ratings" style="border: 1px solid #CCC;overflow: visible;padding: 10px;position: relative;width: 182px;height: 47px;float: left;margin-left: -195px;"><div class="star_1 ratings_stars ratings_vote"></div><div class="star_2 ratings_stars ratings_vote"></div><div class="star_3 ratings_stars ratings_vote"></div><div class="star_4 ratings_stars ratings_blank"></div><div class="star_5 ratings_stars ratings_blank"></div>
</div>
<a href='transporters2.php?CompanyID=<?php echo $cid;?>'><?php print $row['CompanyName']; ?>
</a></div>
</li>
</div>
</div>
</div>
<?php
}//end of while loop
?>
</ul>
</div>
</div>
<script>
function sendcompanyname()
{
var x= document.getElementById("cpn").value;
}
</script>
</body></html>
Transporters2.php
<?php
$db=mysqli_connect("localhost","root","","db1") or die("unable to connect");
include("header.php");
$cname;
if(isset($_GET['CompanyID'])){
$CompanyID = $_GET['CompanyID'];
$get_name= "SELECT * from `transporters` where `CompanyID`='$CompanyID'";
$run_name= mysqli_query($db,$get_name);
while($row_name=mysqli_fetch_array($run_name)){
$cname = $row_name['CompanyName'];}
}
include("settings.php");
connect();
$ids=array(1);
?>
<!DOCTYPE html>
<html>
<head>
<script src="../js/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="../css/rating.css" />
<!--<script type="text/javascript" src="../js/rating.js"></script>-->
<script>
$(document).ready(function() {
$('.ratings_stars').hover(
// Handles the mouseover
function() {
$(this).prevAll().andSelf().addClass('ratings_over');
$(this).nextAll().removeClass('ratings_vote');
},
// Handles the mouseout
function(){
$(this).prevAll().andSelf().removeClass('ratings_over');
}
);
//send ajax request to rate.php
$('.ratings_stars').bind('click', function(){
var id=$(this).parent().attr("id");
var num=$(this).attr("class");
var poststr="id="+id+"&stars="+num;
$.ajax({url:"../bin/rate.php",cache:0,data:poststr,success:function(result){
document.getElementById(id).innerHTML=result;}
});
});
});
</script>
</head>
<body>
<!-- Page Content -->
<div class="container">
<!-- /.row -->
<div class="row">
<?php
for($i=0;$i<count($ids);$i++)
{
$rating_tableName = 'ratings';
$id=$CompanyID;
$q="SELECT total_votes, total_value FROM $rating_tableName WHERE id=$id";
$r=mysql_query($q);
if(!$r) echo mysql_error();
while($row=mysql_fetch_array($r))
{
$v=$row['total_votes'];
$tv=$row['total_value'];
$rat=$tv/$v;
}
$id=$CompanyID;
$j=$id;
echo'<div class="product">
Rate Item '.$j.'
<div id="rating_'.$id.'" class="ratings">';
for($k=1;$k<6;$k++){
if($rat+1>$k)$class="star_".$k."ratings_stars ratings_vote";
else $class="star_".$k." ratings_stars ratings_blank";
echo '<div class="'.$class.'"></div>';
}
echo' <div class="total_votes"><p class="voted"> Rating
<strong>'.#number_format($rat).'</strong>/5 ('.$v. 'vote(s) cast)
</div>
</div></div>';}
?>
<div class="col-lg-12">
<h2 class="page-header"><?php echo $cname;?></h2>
</div>
<!--<div class="col-md-3 col-sm-6">
<div class="panel panel-default text-center">
<div class="panel-heading">
<span class="fa-stack fa-5x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-car fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="panel-body">
<h4>Show Drivers</h4>
<p>Show drivers of this company.</p>
<button id="popup" onclick="div_show()" class="btn btn
primary">Add</button>
</div>
</div>
</div>-->
<div class="col-md-3 col-sm-6">
<div class="panel panel-default text-center">
<div class="panel-heading">
<span class="fa-stack fa-5x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-support fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="panel-body">
<h4>Show routes</h4>
<p>check which routes are following this company...</p>
<a href="routes.php?CompanyID=<?php echo $CompanyID;?>" class="btn btn
primary">show routes</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="panel panel-default text-center">
<div class="panel-heading">
<span class="fa-stack fa-5x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-database fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="panel-body">
<h4>Schedule</h4>
<p>Check the timings of journey.</p>
Show Schedule
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="panel panel-default text-center">
<div class="panel-heading">
<span class="fa-stack fa-5x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-database fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="panel-body">
<h4>Show Drivers Positions</h4>
<p>Check the positions of all drivers.</p>
<a href="positions.php" class="btn btn-primary">Show Drivers
Positions</a>
</div>
</div>
</div>
</div>
</div>
<!---END Page Content-->
</body>
</html>

Bootstrap PHP unknown row in page

I started doing my school project and learning bootstrap basics but i have one problem with php code. I dont know how to delete this row in code.
http://imgur.com/LP0U9CK (or see below)
That red box.
As you can see in properties there is " ". When i delete it, row disappear. My index.php :
http://pastebin.com/K9GEF5mb (or see below):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ryby.sk</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href = "css/bootstrap.min.css" rel = "stylesheet">
<link href = "css/style.css" rel = "stylesheet">
</head>
<body>
<div id="kontajner">
<?php
include("header.php");
?>
<div id="body">
<div class= "container" >
<div class="jumbotron" id="na_stred">
<h1>Vitajte na stránke www.ryby.sk</h1>
<p>Stránka je hlavne zameraná na informácie o sladkovodných rýbach.</p>
</div>
</div>
<div class= "container">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="page-header">
<h2> Akvaristika </h2>
</div>
<p> gvfdgsdfghsf ghhfg hd gdgsdfghsf ghhfg hd gdgsdfghsf ghhfg hd gdgsdfghsf ghhfg hd gdgsdfghsf ghhfg hd gdgsdfghsf ghhfg hd g</p>
<p> Zdroj: lblablalb </p>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="navbar-inverse navbar-default navbar-bottom footer">
<div class="container">
<p class="navbar-text pull-left">Bezo production</p>
<a href="#contact" class=" navbar-btn btn-primary btn-lg disabled btn-sm pull-right" data-toggle="modal" role="button" >Napíšte nám</a>
</div>
</div>
</div>
</div>
</body>
</html>
Everything is OK, but when I add include("header.php"); than this row appears. Can you help me please? I am solving this problem for one week :(
There are two sources for the whitespace in your code. I have indicated them with XXX, and the one newline is indicated by Y in index.php.
In index.php:
<div id="kontajner">
XXXXXXXXXXXXXXXXXXXXXXXX<?php
include("header.php");
?>Y
XXXXXXXXXXXXXXXXXXXXXXXX<div id="body">
And in header.php:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<div class = "navbar navbar-inverse navbar-static-top">
You should keep in mind though, that whitespace does not matter in HTML.
UPDATE:
As #hanzo2001 points out, it's possible to include code as follows:
<div><?php echo "Hello!"; ?></div>
Or to demonstrate the principle more extremely:
<div><?php
if (1==1)
{
echo "Hello!";
}
?></div>
Both of which will render as:
<div>Hello!</div>

Categories