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'm trying to figuring out what the problem but I can't.
Basically I have the index.php with a login to an admin area and admin.php that Is the main page of the admin area.
If I remove the SESSION from the admin.php page the login itself works but I can reach the page admin.php without logging into index, but if I add the SESSION to admin.php after the login it goes straight to the else at the end of the admin.php page.
For sure I'm failing something with the SESSION but I don't know what.
Index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="icon" type="image/png" href="images/favico.png">
<title>eWaste</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="css/mdb.min.css" rel="stylesheet">
<!-- Your custom styles (optional) -->
<link href="css/style.css" rel="stylesheet">
<style>
html{
margin-top: 100px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light grey lighten-5 fixed-top">
<div class="container">
<a class="navbar-brand" href="../index.php">
<img src="../images/logo.png" height="30" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarResponsive">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" id="navi-current" href="index.php">Admin</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Navbar -->
<!--Main-->
<main class="mb-4 pb-5">
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-3"></div>
<div class="col-xl-4 col-lg-4 col-md-6">
<form class="text-center border border-light p-5" method="post" name="">
<p class="h4 mb-4">Sign in</p>
<!-- Email -->
<input type="text" id="materialContactFormUsername" class="form-control" placeholder="User" name="formuser">
<!-- Password -->
<input type="password" id="defaultLoginFormPassword" class="form-control mb-4" placeholder="Password" name="formpass">
<!-- Login button -->
<button class="btn btn-info btn-block my-4" type="submit" name="submit">Sign in</button>
</form>
</div>
<div class="col-xl-4 col-lg-4 col-md-3"></div>
</div>
</div>
</main>
<!--/.Main-->
<?php
if (isset($_POST['submit']))
{
include 'conn.php';
session_start();
$user = $_POST['formuser'];
$pass = $_POST['formpass'];
$query = mysqli_query($conn, "SELECT user FROM login WHERE user='$user' and pass='$pass'");
if (!$query) {
die('Invalid query: ' . mysqli_error());
}
if (mysqli_num_rows($query) != 0){
$_SESSION['login_user']=$username;
header("Location: admin.php");
}
else{
echo "<script type='text/javascript'>alert('User Name Or Password Invalid!')</script>";
}
mysqli_close($conn);
}
?>
<!--Footer-->
<?php include 'footer.php';?>
<!--/.Footer-->
<!-- SCRIPTS -->
<!-- JQuery -->
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- Initializations -->
<script type="text/javascript">
// Animations initialization
new WOW().init();
</script>
</body>
Admin.php
<?php
if (isset($_SESSION['login_user'])){
session_start();
echo "ok";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="icon" type="image/png" href="images/favico.png">
<title>eWaste</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="css/mdb.min.css" rel="stylesheet">
<!-- Your custom styles (optional) -->
<link href="css/style.css" rel="stylesheet">
<style>
html{
margin-top: 100px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light grey lighten-5 fixed-top">
<div class="container">
<a class="navbar-brand" href="../index.php">
<img src="../images/logo.png" height="30" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarResponsive">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" id="navi-current" href="index.php">Admin</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Navbar -->
<!--Main-->
<main class="mb-4 pb-5">
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-3"></div>
<div class="col-xl-4 col-lg-4 col-md-6">
</div>
<div class="col-xl-4 col-lg-4 col-md-3"></div>
</div>
</div>
</main>
<!--/.Main-->
<!--Footer-->
<?php include 'footer.php';?>
<!--/.Footer-->
<!-- SCRIPTS -->
<!-- JQuery -->
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- Initializations -->
<script type="text/javascript">
// Animations initialization
new WOW().init();
</script>
</body>
</html>
<?php
}
else{
echo "no";
exit();
}
?>
Please try to place this code
<?php
if (isset($_POST['submit']))
{
include 'conn.php';
session_start();
$user = $_POST['formuser'];
$pass = $_POST['formpass'];
$query = mysqli_query($conn, "SELECT user FROM login WHERE user='$user' and pass='$pass'");
if (!$query) {
die('Invalid query: ' . mysqli_error());
}
if (mysqli_num_rows($query) != 0){
$_SESSION['login_user']=$username;
header("Location: admin.php");
}
else{
echo "<script type='text/javascript'>alert('User Name Or Password Invalid!')</script>";
}
mysqli_close($conn);
}
?>
At the Start of the page. You can not assign value into the session if you print something on browser. It will give you warnings.
Working since last a month, tried many solutions which I got from google, but not getting anything helpful. Code is working perfectly and fast on localhost. But not on the live server (VPS hosting). Please visit http://97.74.37.64/ link and see it takes forever to filter 14000 mobile numbers in DND and NON-DND numbers. But at my localhost it takes only about 20 seconds to complete the same process. I don't understand the reason and don't have time to waste more on this. Please provide your kind solution as earliest.
PS : This website is using GoDaddy VPS hosting with 4GB of RAM.
Below is the code..
Controller (filter.php)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Filter extends MX_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('Filter_model');
}
public function index()
{
$this->load->view('front_page');
}
public function numbers()
{
set_time_limit(2500);
ini_set('memory_limit', '-1');
//empty the existing table data first
$tru = $this->Filter_model->empty_data();
if (isset($tru))
$mobile_number = $this->input->post('numbers');
//adding comma after each mobile number
if (strpos($mobile_number, "\r\n") !== false) {
$mobile_number = str_replace("\r\n", ',', $mobile_number);
} elseif (strpos($mobile_number, "\n\r") !== false) {
$mobile_number = str_replace("\n\r", ',', $mobile_number);
} elseif (strpos($mobile_number, "\n") !== false) {
$mobile_number = str_replace("\n", ',', $mobile_number);
}
//convert comman seprate string to the array
$mobile_number = explode(",", $mobile_number);
$json_data['number'] = json_encode($mobile_number);
$j_conv = str_replace(']', '', str_replace('"', '', str_replace('[', '', $json_data['number'])));
$e_arr = explode(",", $j_conv);
$res = $this->Filter_model->compare_numbers($e_arr);
$res_nondnd = $this->Filter_model->compare_nondnd_numbers($e_arr);
$array = json_decode(json_encode($res), True);
$array_nondnd = json_decode(json_encode($res_nondnd), True);
//array common words to remove
$common_words = array("e_number]", "=", "n", "0[");
//now convert the data into string again
$url = preg_replace('/[a-z]/', '', str_replace($common_words, '', preg_replace('/&.....[a-z_=]/', ',', urldecode(http_build_query($array)))));
//working here
if (sizeof($mobile_number) <= 15000){
$data['dnd_numbers'] = $array;
$data['not_dnd_numbers'] = $array_nondnd;
$this->load->view('filtered_numbers', $data);
} else {
$this->session->set_flashdata('error', 'Error... Please enter max 15000 numbers at one time');
redirect('filter');
}
}
}
Model (Filter_model.php)
<?php
class Filter_model extends CI_Model {
function __construct() {
parent::__construct();
}
public function empty_data(){
return $this->db->truncate('srchlist');
}
public function compare_numbers($e_arr){
$stmt = "('" . implode("'), ('", $e_arr) . "')";
$ins_res = $this->db->query("INSERT INTO srchlist (number) VALUES $stmt" );
$join_res = $this->db->query("SELECT mobile.phone_number FROM mobile INNER JOIN srchlist ON mobile.phone_number = srchlist.number");
return $join_res->result();
}
public function compare_nondnd_numbers($e_arr){
$join_nondnd_res = $this->db->query("SELECT number FROM `srchlist` F WHERE NOT EXISTS (SELECT phone_number FROM mobile S WHERE F.number = S.phone_number)
");
return $join_nondnd_res->result();
}
public function check_dnd_number($phone_number) {
$this->db->where('phone_number', $phone_number);
$this->db->where('ops_type', 'A');
//$this->db->or_where('ops_type', 'a');
$query = $this->db->get('mobile');
return $query->row('phone_number');
}
public function database_numbers() {
$this->db->select('phone_number');
$this->db->where('ops_type', 'A');
$query = $this->db->get('mobile');
return $query->result();
}
public function scrub_numbers() {
$mobile_number = $this->input->post('numbers');
if (strpos($mobile_number, "\r\n") !== false) {
$mobile_number = str_replace("\r\n", ',', $mobile_number);
} elseif (strpos($mobile_number, "\n\r") !== false) {
$mobile_number = str_replace("\n\r", ',', $mobile_number);
} elseif (strpos($mobile_number, "\n") !== false) {
$mobile_number = str_replace("\n", ',', $mobile_number);
}
$pieces = explode(",", $mobile_number);
if (!empty($pieces) && $pieces[0] != '')
$pieces = array_map(function($v) {
return strlen($v) >= 10 ? substr($v, -10) : $v;
}, $pieces);
$pieces = array_unique($pieces);
$database = $this->database_numbers();
}
}
View (front_page.php)
<!DOCTYPE html>
<html lang="en">
<?php $general = $this->Common_model->get_home(); ?>
<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="<?= $general->metadescription ?>">
<meta name="keyword" content="<?= $general->metadescription ?>">
<meta name="author" content="Jay Chandra || www.shubhtech.in">
<title><?= $general->title ?></title>
<!-- Bootstrap Core CSS -->
<link href="<?= base_url() ?>assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="<?= base_url() ?>assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<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=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<!-- Plugin CSS -->
<link href="<?= base_url() ?>assets/vendor/magnific-popup/magnific-popup.css" rel="stylesheet">
<!-- Theme CSS -->
<link href="<?= base_url() ?>assets/css/creative.min.css" rel="stylesheet">
<!-- 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="<?= base_url() ?>assets/https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="<?= base_url() ?>assets/https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top">
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<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> Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand page-scroll" href="<?= base_url() ?>#page-top"><?= $general->sitename ?></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a class="page-scroll" href="<?= base_url() ?>#contact">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<header>
<div class="header-content">
<div class="header-content-inner">
<marquee direction="left" behavior="scroll" scrollamount="5" scrolldelay="100" onMouseOver="stop()" onMouseOut="start()">
<p><?= $general->marquee ?></p>
</marquee>
<p>To filter, You can enter multiple number by one number per line or one number by comma e.g: 8877665544, 9876543210.</p>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<form method="post" action="<?= base_url() ?>filter/numbers/#result">
<div class="form-group">
<textarea name="numbers" class="form-control" rows="10" autofocus=""></textarea>
<p>(You can filter 15,000 mobile numbers at one time)</p>
</div>
<div class="form-group">
<input type="submit" class="btn btn-lg btn-success" value="SCRUB IT"/>
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-lg-12">Space for Ad</div>
</div>
</div>
</div>
</header>
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h2 class="section-heading">Let's Get In Touch!</h2>
<hr class="primary">
</div>
<div class="col-lg-4 col-lg-offset-2 text-center">
<i class="fa fa-phone fa-3x sr-contact"></i>
<p><?= $general->contact ?></p>
</div>
<div class="col-lg-4 text-center">
<i class="fa fa-envelope-o fa-3x sr-contact"></i>
<p><?= $general->email ?></p>
</div>
</div>
</div>
</section>
<!-- jQuery -->
<script src="<?= base_url() ?>assets/vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<?= base_url() ?>assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
<script src="<?= base_url() ?>assets/https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<script src="<?= base_url() ?>assets/vendor/scrollreveal/scrollreveal.min.js"></script>
<script src="<?= base_url() ?>assets/vendor/magnific-popup/jquery.magnific-popup.min.js"></script>
<!-- Theme JavaScript -->
<script src="<?= base_url() ?>assets/js/creative.min.js"></script>
</body>
</html>
filter number showing view (filtered_numbers.php)
<!DOCTYPE html>
<html lang="en">
<?php $general = $this->Common_model->get_home(); ?>
<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="<?= $general->metadescription ?>">
<meta name="keyword" content="<?= $general->metadescription ?>">
<meta name="author" content="Jay Chandra || www.shubhtech.in">
<title><?= $general->title ?></title>
<!-- Bootstrap Core CSS -->
<link href="<?= base_url() ?>assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="<?= base_url() ?>assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<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=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<!-- Plugin CSS -->
<link href="<?= base_url() ?>assets/vendor/magnific-popup/magnific-popup.css" rel="stylesheet">
<!-- Theme CSS -->
<link href="<?= base_url() ?>assets/css/creative.min.css" rel="stylesheet">
<!-- 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="<?= base_url() ?>assets/https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="<?= base_url() ?>assets/https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top">
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<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> Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand page-scroll" href="<?= base_url() ?>#page-top"><?= $general->sitename ?></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a class="page-scroll" href="<?= base_url() ?>#contact">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<header>
<div class="header-content">
<div class="header-content-inner">
<marquee direction="left" behavior="scroll" scrollamount="5" scrolldelay="100" onMouseOver="stop()" onMouseOut="start()">
<p><?= $general->marquee ?></p>
</marquee>
<p>To filter, You can enter multiple number by one number per line or one number by comma e.g: 8877665544, 9876543210.</p>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<form method="post" action="<?= base_url() ?>filter/numbers/#result">
<div class="form-group">
<textarea name="numbers" class="form-control" rows="10" autofocus=""></textarea>
<p>(You can filter 15,000 mobile numbers at one time)</p>
</div>
<div class="form-group">
<input type="submit" class="btn btn-lg btn-success" value="SCRUB IT"/>
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-lg-12">Space for Ad</div>
</div>
</div>
</div>
</header>
<section class="bg-primary" id="result">
<div class="container">
<div class="row">
<div class="col-lg-4 col-lg-offset-2 text-center">
<h2 class="section-heading">DND Numbers</h2>
<hr class="light">
<textarea class="form-control" rows="20"><?php
foreach ($dnd_numbers as $list) {
echo "$list[phone_number]\r\n";
}
?></textarea>
</div>
<div class="col-lg-4 text-center">
<h2 class="section-heading">NON DND Numbers</h2>
<hr class="light">
<textarea class="form-control" rows="20"><?php
foreach ($not_dnd_numbers as $list) {
echo "$list[number]\r\n";
}
?></textarea>
</div>
</div>
</div>
</section>
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h2 class="section-heading">Let's Get In Touch!</h2>
<hr class="primary">
</div>
<div class="col-lg-4 col-lg-offset-2 text-center">
<i class="fa fa-phone fa-3x sr-contact"></i>
<p><?= $general->contact ?></p>
</div>
<div class="col-lg-4 text-center">
<i class="fa fa-envelope-o fa-3x sr-contact"></i>
<p><?= $general->email ?></p>
</div>
</div>
</div>
</section>
<!-- jQuery -->
<script src="<?= base_url() ?>assets/vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<?= base_url() ?>assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
<script src="<?= base_url() ?>assets/https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<script src="<?= base_url() ?>assets/vendor/scrollreveal/scrollreveal.min.js"></script>
<script src="<?= base_url() ?>assets/vendor/magnific-popup/jquery.magnific-popup.min.js"></script>
<!-- Theme JavaScript -->
<script src="<?= base_url() ?>assets/js/creative.min.js"></script>
</body>
</html>
When I try to return a view from a route like this:
Route::get('/testid', function () {
$id = 1; // for test only
$title = 'Dashboard';
$username=Auth::user()->name;
$job=Auth::user()->job;
$p = 1;
$requestedorder = \App\Order::findOrfail($id);
return view('ViewOrder',compact('requestedorder','title','username','job','p'));
});
in the browser it shows up normally like any bootstrap view
but when this view is returned from a controller
public function show($id)
{
$title = 'Dashboard';
$username=Auth::user()->name;
$job=Auth::user()->job;
$p = 1;
$requestedorder = Order::findOrfail($id);
return view('ViewOrder',compact('requestedorder','title','username','job','p'));
}
the view be like this without any bootstrap or any css or even without images : http://1drv.ms/1m7N8Yk
I noticed that this problem occures in any url with id like this "http://localhost:8000/testid/1"
this is vieworder view
#extends('WDashBoard')
#section('content2')
<div>
<h1>Order Details</h1>
<hr>
<div class="row">
<div class="col-sm-3">
<h5><B>From :</B></h5>
</div>
<div class="col-sm-9">
<h5> {{ $requestedorder->customeremail }}</h5>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<h5><B>Details :</B></h5>
</div>
<div class="col-sm-9">
<h5>{{ $requestedorder->details }}</h5>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<h5><B>Required Work :</B></h5>
</div>
<div class="col-sm-9">
<h5>{{ $requestedorder->requiredwork }}</h5>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<h5><B>Date :</B></h5>
</div>
<div class="col-sm-9">
<h5> {{ $requestedorder->date }}</h5>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<h5><B>Time :</B></h5>
</div>
<div class="col-sm-9">
<h5>{{ $requestedorder->time }}</h5>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<h5><B>Message :</B></h5>
</div>
<div class="col-sm-9">
<h5>{{ $requestedorder->message }}</h5>
</div>
</div>
</div>
#stop
and this is my DashBoard view
#extends('master')
#section('content')
<section class="slider2">
<div class="slider-wrap2">
<h1>DashBoard</h1>
</div>
</section>
<section class="container">
<div class="row">
<div class="col-sm-3">
<div class="dash">
<br><br>
<center><img src="images/default-avatar.png" class="img-responsive img-circle" /></center>
<center><h3> {{ $username }} </h3></center>
<center><h4> {{ $job }} </h4></center>
<br>
<ul class="nav nav-pills nav-stacked">
<li class="nav-header"></li>
<li><a href="/profile"><i class="glyphicon glyphicon-list-alt"></i>
My Profile</a></li>
<li class="divider"></li>
<li><a href="/orders"><i class="glyphicon glyphicon-briefcase"></i>
Requested Orders</a></li>
</ul>
<br><br><br><br>
</div>
</div>
<div class="col-sm-9">
#yield('content2')
</div>
</div>
<br>
</section>
#stop
and this is master view
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ $title }}</title>
<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS
================================================== -->
<!-- Bootstrap -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<!-- FontAwesome -->
<link rel="stylesheet" href="css/font-awesome.min.css">
<!-- Elegant icon font -->
<link rel="stylesheet" href="css/line-icons.min.css">
<!-- Animation -->
<link rel="stylesheet" href="css/animate.css">
<!-- Prettyphoto -->
<link rel="stylesheet" href="css/prettyPhoto.css">
<!-- Owl Carousel -->
<link rel="stylesheet" href="css/owl.carousel.css">
<link rel="stylesheet" href="css/owl.theme.css">
<!-- Scrolling nav css -->
<link rel="stylesheet" href="css/scrolling-nav.css">
<!-- Template styles-->
<link rel="stylesheet" href="css/style.css">
<!-- Responsive styles-->
<link rel="stylesheet" href="css/responsive.css">
<!-- HTML5 shim and Respond.js for 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/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 data-spy="scroll" data-target=".navbar-fixed-top" >
<!-- Header start -->
<header id="header" role="banner" >
<nav class="navbar navbar-default navbar-fixed-top" id="tf-menu">
<div class="container">
<div class="row">
<!-- Logo start -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand">
<a href="#" class="page-scroll">
<img class="img-responsive" src="images/logo1.png" alt="logo">
</a>
</div>
</div><!--/ Logo end -->
<div class="collapse navbar-collapse clearfix navMenu" role="navigation">
<ul class="nav navbar-nav navbar-right">
<li><a class="page-scroll" href="/" >Home</a></li>
<li><a class="page-scroll" href="/about" >About</a></li>
<li><font style="opacity:.1">....................</font></li>
#if($p == 0)
<li><a href="/login" ><small>SignIn</small></a></li>
<li><small>Register</small></li>
#endif
#if($p == 1)
<li><a href="/profile" ><small>hi {{ $username }}</small></a></li>
<li><small>Logout</small></li>
#endif
</ul>
</div><!--/ Navigation end -->
</div><!--/ Row end -->
</div><!--/ Container end -->
</nav>
</header><!--/ Header end -->
<!-- END MAIN NAV -->
#yield('content')
<!-- section Footer start -->
<footer id="footer">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="footer-content text-center">
<a href="#slider-part" class="page-scroll logo-title">
<img src="images/blackbg.png" alt="" class="img-responsive">
</a>
<ul class="footer-socail list-inline">
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-linkedin"></i></li>
</ul>
</div>
<hr>
<div class="row">
<div class="col-md-6">
<div class="copyright">
<p> copyright © <span>mycompany</span> - 2015</p>
</div>
</div>
<div class="col-md-6">
</div>
</div>
</div>
</div> <!-- row end -->
</div> <!-- container end -->
</footer>
<!-- section Footer end -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="assets/js/bootstrap.min.js"></script>
<!-- initialize jQuery Library -->
<script type="text/javascript" src="js/jquery.js"></script>
<!-- Bootstrap jQuery -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- Style Switcher -->
<script type="text/javascript" src="js/isotope.js"></script>
<!-- Owl Carousel -->
<script type="text/javascript" src="js/owl.carousel.js"></script>
<!-- PrettyPhoto -->
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<!-- Isotope -->
<script type="text/javascript" src="js/isotope.js"></script>
<!-- Wow Animation -->
<script type="text/javascript" src="js/wow.min.js"></script>
<!-- SmoothScroll -->
<script type="text/javascript" src="js/smooth-scroll.js"></script>
<!-- Eeasing -->
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<!-- Counter -->
<script type="text/javascript" src="js/jquery.counterup.min.js"></script>
<!-- Waypoints -->
<script type="text/javascript" src="js/jquery.waypoints.min.js"></script>
<!-- Scrolling navigation -->
<script type="text/javascript" src="js/scrolling-nav.js"></script>
<!-- Google Map API Key Source -->
<!--<script src="http://maps.google.com/maps/api/js?sensor=false"></script>-->
<!-- Custom js -->
<script type="text/javascript" src="js/custom.js"></script>
<script type="text/javascript" src="js/mapjs.js"></script>
<script>
new WOW().init();
</script>
<script>
$('.counter').counterUp({
delay: 100,
time: 2000
});
</script>
</body>
</html>
please help me
thanks in advance
I'm assuming you're using relative paths in your HTML that are not properly mapping to your assets through your 'folder' structure.
Have you wrapped your asset URLs in the asset() helper function in your view?
<link href="{{ asset( 'path/to/asset' ) }}" rel="stylesheet">
<img src="{{ asset( 'path/to/image' ) }}">
Remember, use of the / means you're in a 'subfolder' in traditional URL-to-Unix-style path mapping, so your asset references need to account for that.
Thankfully, Laravel makes this super easy with the URL helper functions.
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>