Im getting the typical unexpected end of file
i cant see what I'm missing can someone else please help i've gone code blind
<?php
session_start();
include('config.php');
include('funcs.php');
date_default_timezone_set('Europe/London');
if(!in_array($_SESSION['userid'],$adminusr)){
header("Location: index.html");
}
?>
<html><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="css.css" rel="stylesheet" type="text/css">
</head><body>
<div class="navbar navbar-default navbar-static-top" style="height:55px; background-color:#FFFFFF; border-bottom:#FF6600 2px solid;">
<div class="container">
<div class="navbar-header" style="height:60px;">
<button type="button" class="navbar-toggle hidden-xs" data-toggle="collapse" data-target="#navbar-ex-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" style="padding-top:5px;"><img height="45" alt="Brand" src="logo.jpg"></a>
</div>
<div class="collapse navbar-collapse hidden-xs hidden-sm" id="navbar-ex-collapse">
<ul class="nav navbar-nav navbar-right">
<li>
Jobs
</li>
<li>
Servicing
</li>
<li>
Prep
</li>
<li>
Finances
</li>
<li>
+ New Job
</li>
</ul>
</div>
</div>
</div>
<div class="section">
<div class="hidden-lg hidden-md hidden-sm">
<ul class="nav nav-pills nav-justified">
<li>
Jobs
</li>
<li>
Servicing
</li>
<li>
Prep
</li>
<li>
Finances
</li>
<li>
+ New Job
</li>
</ul>
</div>
</div>
<div class="section text-justify" style="padding-bottom:0px;">
<div class="container">
<div class="row">
<div class="col-md-offset-3 col-md-6">
<form role="form">
<div class="form-group">
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="Search for something ...">
<span class="input-group-btn">
<a class="btn btn-link" type="submit"><i class="fa fa-lg fa-search"></i></a>
</span>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="section text-center">
<div class="container">
<div class="row">
<div class="col-md-4 text-left">
<h3>
<i class="fa fa-cogs fa-fw fa-lg text-orange"></i>Current Jobs :</h3>
<?php
// List Jobs With Closest Req. By Date
$curdate = date('Y-m-d');
$listjobsq = mysqli_query($con,"SELECT * FROM `workshop-jobs` WHERE status != 'Completed' AND completed ='0' ORDER BY reqbydate ASC LIMIT 0,10");
$listjobs = mysqli_fetch_assoc($listjobsq);
?>
<ul class="list-group" style="border:none;">
<?php do {
// Job Time Frame Check
$cur = strtotime($curdate);
$req = strtotime($listjobs['reqbydate']);
$diff = floor(abs($req - $cur) / 86400);
$diffdays = ' Days';
$diffbg = 'background-color:#1EBB1B; color:#000000;';
if($req < $cur) { $diff = 'OVERDUE';$diffdays = '';$diffbg = 'background-color:#FF0000; color:#FFFFFF;';}
if($req == $cur) { $diff = 'TODAY';$diffdays = '';$diffbg = 'background-color:#F8C000; color:#000000;';}
if($diff == 1) { $diff = 'TOMORROW';$diffdays = '';$diffbg = 'background-color:#F8C000; color:#000000;';}
if($diff >= 2){ if($diff <= 7){$diffdays = ' Days';$diffbg = 'background-color:#F8C000; color:#000000;';} }
// End
// User Query
$wscid = $listjobs['wscid'];
$userq = mysqli_query($cona,"SELECT * FROM `users` WHERE userid = '$wscid'");
$user = mysqli_fetch_assoc($userq);
?>
<li class="list-group-item text-right" style="border:none;"><span class="badge pull-left" style="<?php echo $diffbg;?>"><?php echo $diff. $diffdays;?></span><?php echo $user['forename'].' '.$user['surname'].' - ' .$listjobs['summary'];?></li>
<? } while($listjobs = mysqli_fetch_assoc($listjobsq));?>
<li class="list-group-item text-center" style="border:none;"> -- View All Jobs -- </li>
</ul>
<hr>
</div>
<div class="col-md-4 text-left">
<h3>
<i class="fa fa-fw fa-lg fa-wrench text-orange"></i>Services / Work Due :</h3>
<ul class="list-group">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
<hr>
</div>
<!--?php if($_SESSION[ 'stafflvl']=='administrator' || $_SESSION[ 'stafflvl']=='superadministrator'
){ ?-->
<div class="col-md-4 text-left">
<h3>
<i class="fa fa-fw fa-lg fa-money text-orange"></i>Finance & Invoicing :</h3>
<ul class="list-group">
<?php
$uninvoicedq = mysqli_query($con,"SELECT * FROM `workshop-jobs` WHERE completed = '1' AND invoiced = '0' AND wscid !='0' ORDER BY workstartdate ASC");
$uninvoiced = mysqli_fetch_assoc($uninvoicedq);
if($uninvoiced) {
do {
// User Query
$wscid = $uninvoiced['wscid'];
$userq = mysqli_query($cona,"SELECT * FROM `users` WHERE userid = '$wscid'");
$user = mysqli_fetch_assoc($userq);
$wtbdq = mysqli_query($con,"SELECT * FROM `workshop-jobs` WHERE wsjid = '$uninvoiced[wsjid]'");
$wtbdr = mysqli_fetch_assoc($wtbdq);
do {
$price = '';
$wtbd = explode(":",$wtbdr['worktobedone']);
foreach($wtbd as $item)
{
$priceq = mysqli_query($con,"SELECT * FROM `workshop-items` WHERE wsiid = '$item'");
$pricer = mysqli_fetch_assoc($priceq);
$price[] = $pricer['incvat'];
$items[] = $pricer['description'];
//echo $item.' - '. $pricer['incvat'].'<br>';
$total = array_sum($price);
}
} while($wtbdr = mysqli_fetch_assoc($wtbdq));
?>
<?
$itemList = implode(":",$items);
$itemview = str_replace(":","\n",$itemList);
?>
<li class="list-group-item text-right" style="border:none;" title="<?php echo $itemview;?>"><span class="badge pull-left" style="background-color:#F00;">Not Invoiced</span><?php echo '£'.$total.' - '; echo $user['forename'].' '.$user['surname'].' - ' .$uninvoiced['summary'];?> </li>
<? } while($uninvoiced = mysqli_fetch_assoc($uninvoicedq));} else { echo "No Jobs Waiting To Invoiced";}?>
</ul>
<hr>
</div>
<?php //echo $_SESSION[ 'admin'];?-->?>
</div>
</div>
</div>
</body></html>
I have looked over all of my code but i am pulling my hair out now..
could really do with a fresh pair of eyes having a gander please
<?php
session_start();
include('config.php');
include('funcs.php');
date_default_timezone_set('Europe/London');
if (!in_array($_SESSION['userid'], $adminusr)) {
header("Location: index.html");
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"
type="text/css">
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="navbar navbar-default navbar-static-top"
style="height:55px; background-color:#FFFFFF; border-bottom:#FF6600 2px solid;">
<div class="container">
<div class="navbar-header" style="height:60px;">
<button type="button" class="navbar-toggle hidden-xs" data-toggle="collapse"
data-target="#navbar-ex-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" style="padding-top:5px;"><img height="45" alt="Brand" src="logo.jpg"></a>
</div>
<div class="collapse navbar-collapse hidden-xs hidden-sm" id="navbar-ex-collapse">
<ul class="nav navbar-nav navbar-right">
<li>
Jobs
</li>
<li>
Servicing
</li>
<li>
Prep
</li>
<li>
Finances
</li>
<li>
+ New Job
</li>
</ul>
</div>
</div>
</div>
<div class="section">
<div class="hidden-lg hidden-md hidden-sm">
<ul class="nav nav-pills nav-justified">
<li>
Jobs
</li>
<li>
Servicing
</li>
<li>
Prep
</li>
<li>
Finances
</li>
<li>
+ New Job
</li>
</ul>
</div>
</div>
<div class="section text-justify" style="padding-bottom:0px;">
<div class="container">
<div class="row">
<div class="col-md-offset-3 col-md-6">
<form role="form">
<div class="form-group">
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="Search for something ...">
<span class="input-group-btn">
<a class="btn btn-link" type="submit"><i class="fa fa-lg fa-search"></i></a>
</span>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="section text-center">
<div class="container">
<div class="row">
<div class="col-md-4 text-left">
<h3>
<i class="fa fa-cogs fa-fw fa-lg text-orange"></i>Current Jobs :</h3>
<?php
// List Jobs With Closest Req. By Date
$curdate = date('Y-m-d');
$listjobsq = mysqli_query($con, "SELECT * FROM `workshop-jobs` WHERE status != 'Completed' AND completed ='0' ORDER BY reqbydate ASC LIMIT 0,10");
$listjobs = mysqli_fetch_assoc($listjobsq);
?>
<ul class="list-group" style="border:none;">
<?php do {
// Job Time Frame Check
$cur = strtotime($curdate);
$req = strtotime($listjobs['reqbydate']);
$diff = floor(abs($req - $cur) / 86400);
$diffdays = ' Days';
$diffbg = 'background-color:#1EBB1B; color:#000000;';
if ($req < $cur) {
$diff = 'OVERDUE';
$diffdays = '';
$diffbg = 'background-color:#FF0000; color:#FFFFFF;';
}
if ($req == $cur) {
$diff = 'TODAY';
$diffdays = '';
$diffbg = 'background-color:#F8C000; color:#000000;';
}
if ($diff == 1) {
$diff = 'TOMORROW';
$diffdays = '';
$diffbg = 'background-color:#F8C000; color:#000000;';
}
if ($diff >= 2) {
if ($diff <= 7) {
$diffdays = ' Days';
$diffbg = 'background-color:#F8C000; color:#000000;';
}
}
// End
// User Query
$wscid = $listjobs['wscid'];
$userq = mysqli_query($cona, "SELECT * FROM `users` WHERE userid = '$wscid'");
$user = mysqli_fetch_assoc($userq);
?>
<li class="list-group-item text-right" style="border:none;"><span class="badge pull-left"
style="<?php echo $diffbg; ?>"><?php echo $diff . $diffdays; ?></span><a
href="job.php?wsjid=<?php echo $listjobs['wsjid']; ?>"
style="color:#000;"><?php echo $user['forename'] . ' ' . $user['surname'] . ' - ' . $listjobs['summary']; ?></a>
</li>
<?php } while ($listjobs = mysqli_fetch_assoc($listjobsq)); ?>
<li class="list-group-item text-center" style="border:none;"><a href="viewjobs.php"
style="color:#000; font-size:14px; font-weight:bold;">
-- View All Jobs -- </a></li>
</ul>
<hr>
</div>
<div class="col-md-4 text-left">
<h3>
<i class="fa fa-fw fa-lg fa-wrench text-orange"></i>Services / Work Due :</h3>
<ul class="list-group">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
<hr>
</div>
<!--?php if($_SESSION[ 'stafflvl']=='administrator' || $_SESSION[ 'stafflvl']=='superadministrator'
){ ?-->
<div class="col-md-4 text-left">
<h3>
<i class="fa fa-fw fa-lg fa-money text-orange"></i>Finance & Invoicing :</h3>
<ul class="list-group">
<?php
$uninvoicedq = mysqli_query($con, "SELECT * FROM `workshop-jobs` WHERE completed = '1' AND invoiced = '0' AND wscid !='0' ORDER BY workstartdate ASC");
$uninvoiced = mysqli_fetch_assoc($uninvoicedq);
if ($uninvoiced) {
do {
// User Query
$wscid = $uninvoiced['wscid'];
$userq = mysqli_query($cona, "SELECT * FROM `users` WHERE userid = '$wscid'");
$user = mysqli_fetch_assoc($userq);
$wtbdq = mysqli_query($con, "SELECT * FROM `workshop-jobs` WHERE wsjid = '$uninvoiced[wsjid]'");
$wtbdr = mysqli_fetch_assoc($wtbdq);
do {
$price = '';
$wtbd = explode(":", $wtbdr['worktobedone']);
foreach ($wtbd as $item) {
$priceq = mysqli_query($con, "SELECT * FROM `workshop-items` WHERE wsiid = '$item'");
$pricer = mysqli_fetch_assoc($priceq);
$price[] = $pricer['incvat'];
$items[] = $pricer['description'];
//echo $item.' - '. $pricer['incvat'].'<br>';
$total = array_sum($price);
}
} while ($wtbdr = mysqli_fetch_assoc($wtbdq));
?>
<?php
$itemList = implode(":", $items);
$itemview = str_replace(":", "\n", $itemList);
?>
<li class="list-group-item text-right" style="border:none;"
title="<?php echo $itemview; ?>"><span class="badge pull-left"
style="background-color:#F00;">Not Invoiced</span><?php echo '£' . $total . ' - ';
echo $user['forename'] . ' ' . $user['surname'] . ' - ' . $uninvoiced['summary']; ?>
</li>
<?php } while ($uninvoiced = mysqli_fetch_assoc($uninvoicedq));
} else {
echo "No Jobs Waiting To Invoiced";
} ?>
</ul>
<hr>
</div>
<?php //echo $_SESSION[ 'admin'];?-->?>
</div>
</div>
</div>
</body>
</html>
try this once
tou are missing a } at end. make sure that you ended if($uninvoiced) { on line 152.
Related
i'm new to web development; I have been trying to populate bootstrap pills dynamically from the database, generating the pill itself and also the content dynamically. So far only the Pills are being generated but the contents don't seem to be generated. The pills are meant to display contents that are individual pdf files obtained from the database sorted based on the category matching the pill being iterated in the while loop. Here is my code. Thanks.
//HTML Bootstrap
<div class="row bd-sidebar">
<div class="col-2 border-right">
<h3 class="pl-2">Categories</h3><hr>
<div class="nav flex-column nav-pills overflow-auto" id="v-nav-tab" role="tablist" aria-orientation="vertical">
<?php include_once '.assets/_server/category_data.php'; ?>
<?php echo $category_menu; ?>
<div class="col-10">
<div class="tab-content" id="v-pills-tabContent">
<?php echo $category_content;?>
</div>
</div>
</div>
</div>
</div>
//category_data.php
<?php
include_once("dbConfig.php");
$query = "SELECT * FROM `categories` GROUP BY `categoryName` ";
$categoryResult = mysqli_query($link, $query);
$category_menu = "";
$category_content = "";
$count = 0;
while($row = mysqli_fetch_array($categoryResult)){
$value = $row['categoryId'];
$categoryName = $row['categoryName'];
if($count == 0){
$category_menu .= '
<a class="nav-link active" id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade show active" id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="row">
';
}else{
$category_menu .= '
<a class="nav-link" id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade" id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="row">
';
}
$content_query = "SELECT * FROM `books` WHERE `categoryId` = '.$value.' GROUP BY `file_name`";
$content_result = mysqli_query($link, $content_query);
while($sub_row = mysqli_fetch_array($content_result)){
$category_content .= '
</div>
<div class="col-1">
<a class="material text-secondary text-decoration-none" href=".assets/pdf.js/web/viewer.html?file=materials/'.$sub_row['file_name'].'" data-toggle="tooltip" data-delay="300" data-animation="" data-html="true" title="'.$sub_row['file_name'].'">
<div class="mycard justify-content-center" style="width: 7rem;">
<img style="width: 70px; height: 70px;" src="img/book-thumbs/pdf_ico.png" class="mx-auto d-block" alt="pdf thumbnail">;
<div class="bookcardTitle">
<p class="text-center" id="bookcardTitle">'.$sub_row['file_name'].'</p>
</div>
</div>
</a>
</div>
';
}
$category_content .= '<div style="clear:both"></div></div></div>';
$count++;
}
?>
The immediate error in your code is the $content_query line:
$content_query = "SELECT * FROM `books` WHERE `categoryId` = '.$value.' GROUP BY `file_name`";
The string is quoted with double quotes but the $value part is surrounded by single quotes. The solution would be to replace the quotes:
$content_query = "SELECT * FROM `books` WHERE `categoryId` = ".$value." GROUP BY `file_name`";
You can see how the syntax highlight shows the error.
But there's a deeper problem here regarding sql injection. You should not concatenate values obtained from somewhere else in a query. Please see this question: How can I prevent SQL injection in PHP? and this website: https://phpdelusions.net/sql_injection for more information.
<?php
include_once("dbConfig.php");
$query = "SELECT * FROM `categories` GROUP BY `categoryName` ";
$categoryResult = mysqli_query($link, $query);
$category_menu = "";
$category_content = "";
$count = 0;
while($row = mysqli_fetch_array($categoryResult)){
$value = $row['categoryId'];
$categoryName = $row['categoryName'];
if($count == 0){
$category_menu .= '
<a class="nav-link " id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade " id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="nav justify-content-center navbar-light bg-light">
<form class="form-inline v-pills-search" action="">
<input class="form-control rounded-pill mr-2" type="search" name="query" id="book_query" placeholder="Search...">
<button class="btn rounded-pill btn-outline-primary my-2 my-sm-0" type="submit"><i class="fas fa-search"></i></button>
</form>
</div>
<div class="row">
';
}else{
$category_menu .= '
<a class="nav-link" id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade" id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="nav justify-content-center navbar-light bg-light">
<form class="form-inline v-pills-search" action="">
<input class="form-control rounded-pill mr-2" type="search" name="query" id="book_query" placeholder="Search...">
<button class="btn rounded-pill btn-outline-primary my-2 my-sm-0" type="submit"><i class="fas fa-search"></i></button>
</form>
</div>
<div class="row">
';
}
$content_query = "SELECT * FROM `books` WHERE `categoryId` = '".$row['categoryId']."' GROUP BY `file_name`";
$content_result = mysqli_query($link, $content_query);
if(mysqli_num_rows($content_result) < 0) {
$conRow_html .= '<br>No items found in this category!';
}
while($sub_row = mysqli_fetch_array($content_result)){
$category_content .= '
<div class="col-1 mr-4">
<a class="material text-secondary text-decoration-none" href=".assets/pdf.js/web/viewer.html?file=materials/'.$sub_row['file_name'].'" data-toggle="tooltip" data-delay="0" data-animation="true" data-html="true" title="'.$sub_row['file_name'].'">
<div class="mycard justify-content-center" style="width: 7rem;">
<img style="width: 70px; height: 70px;" src="img/book-thumbs/pdf_ico.png" class="mx-auto d-block" alt="pdf thumbnail">
<div class="bookcardTitle">
<p class="text-center book_name" id="bookcardTitle">'.$sub_row['file_name'].'</p>
</div>
</div>
</a>
</div>
';
}
$category_content .= '<div class="clear:both"></div></div></div>';
$count++;
}
?>
I am new to PHP. When I create the below code following tutorial, I am puzzle why I can't update my data to database. As it shows below error
"Something went wrong, please try again"
Can anyone help to see through my scripts on where did I go wrong? Or is there anyway that I can do step by step debug to find out which line goes wrong?
<?php require_once("Includes/DB.php"); ?>
<?php require_once("Includes/Functions.php"); ?>
<?php require_once("Includes/Sessions.php"); ?>
<?php
if (isset($_POST["Submit"]))
{
$PostTitle = $_POST["PostTitle"];
$Category = $_POST["Category"];
$Image = $_FILES["Image"]["name"];
$Target = "Upload/".basename($_FILES["Image"]["name"]);
$PostText = $_POST["PostDescription"];
$Admin = "Sharon";
date_default_timezone_set("Asia/Singapore");
$CurrentTime=time();
$DateTime=strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
if(empty($PostTitle))
{
$_SESSION["ErrorMessage"] = "Title Can't be empty";
Redirect_to("AddNewPost.php");
} elseif (strlen($PostTitle)<5) {
$_SESSION["ErrorMessage"] = "Post Title should be greater
than 5 characters";
Redirect_to("AddNewPost.php");
} elseif (strlen($PostText)>999) {
$_SESSION["ErrorMessage"] = "Post Description should be less than 1000
characters";
Redirect_to("AddNewPost.php");
} else {
// Query to insert Post in DB when everything is fine
global $ConnectingDB;
$sql="INSERT INTO posts(datetime,title,category,author,image,post)";
$sql.="VALUES
:dateTime,:postTitle,:categoryName,:adminName,:imageName,:postDescription
)";
$stmt=$ConnectingDB->prepare($sql); // - > means PDO object rotation
$stmt->bindValue(':dateTime',$DateTime);
$stmt->bindValue(':postTitle',$PostTitle);
$stmt->bindValue(':categoryName',$Category);
$stmt->bindValue(':adminName',$Admin);
$stmt->bindValue(':imageName',$Image);
$stmt->bindValue(':postDescription',$PostText);
$Execute=$stmt->execute();
move_uploaded_file($_FILES["Image"]["tmp_name"],$Target);
if($Execute)
{
$_SESSION["SuccessMessage"]="Post Added Successfully";
Redirect_to("AddNewPost.php");
} else {
$_SESSION["ErrorMessage"]="Something went wrong, please
try again";
Redirect_to("AddNewPost.php");
}
}
} //Ending of Submit Button If- Condition
?>
<!DOCTYPE>
<html lang="en">
<head>
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
integrity="sha384-
fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
crossorigin="anonymous">
<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 rel="stylesheet" href="css/Styles.css">
<title>Categories</title>
</head>
<body>
<div style="height:10px; Background:#27aae1;"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container" ">
<a href="#" class="navbar-brand"> Application
Department </a>
<button class="navbar-toggler" data-
toggle="collapse" data-target="#navbarcollapseCMS">
<span class="navbar-toggler-
icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarcollapseCMS">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a href="Main.php" class="nav-
link"><i class="fas fa-home text-success"></i> Main page </a>
</li>
<li class="nav-item">
<a href="Post.php" class="nav-
link"> Posts </a>
</li>
<li class="nav-item">
<a href="Categories.php"
class="nav-link"> Categories</a>
</li>
<li class="nav-item">
Admin
</li>
<li class="nav-item">
<a href="Comment.php"
class="nav-link"> Comments</a>
</li>
</ul>
<ui class="navbar-nav ml-auto">
<li class="nav-item"><a
href="Logout.php" class="nav-link text-warning"><i class="fas fa-user-
times"></i> Logout</a></li>
</ul>
</div>
</div>
</nav>
<div style="height:10px; Background:#27aae1;"></div>
<!--NAVBAR END-->
<!--header-->
<header class="bg-dark text-white py-3">
<div class="container">
<div class="row">
<div class="col-md-12">
<p style="font-size:30px;"> <i class="fas fa-edit"
style="color:#27aae1;"></i> Add New Post </p>
</div>
</div>
</div>
</header>
<!--header end-->
<!--Main Area -->
<section class="container py-2 mb-4">
<div class="row">
<div class="offset-lg-1 col-lg-10" style="min-height:420px;">
<?php
echo ErrorMessage();
echo SuccessMessage();
?>
<form class="" action="AddNewPost.php" method="post"
enctype="multipart/form-data">
<div class="card bg-secondary text-
light mb-2">
<div class="card-body bg-dark">
<div class="form-group">
<label for="title"> <span class="FieldInfo"> Post Title: </span></label>
<input class="form-control" type="text" name="PostTitle" id="title"
placeholder="Type title here" value="">
</div>
<div
class="form-group">
<label
for="CategoryTitle"> <span class="FieldInfo"> Choose Category:
</span></label>
<select
class="form-control" id="CategoryTitle" name="Category">
<?php
//Fetching all the categories from category mysql_list_tables
global $ConnectingDB;
$sql = "SELECT id,title FROM category";
$stmt = $ConnectingDB->query($sql);
while ($DateRows = $stmt->fetch()) {
$Id = $DateRows["id"];
$CategoryName = $DateRows["title"];
?>
<option> <?php echo $CategoryName; ?> </option>
<?php } ?>
</select>
</div>
Good afternoon,
I am working on a website for a friend's gaming fansite. Utilizing a URI function and ajax URL loads, I'm setting it up so when they visit a page, the URL changes and that page's content loads, while leaving the top portion of the website static. The logo, radio box and navigation bar is the static portion.
Everything is working as intended so far, but when a page is used that's using a specific ID, it loads up a blank page. I'll show what I've done with the Badges page for an example.
Here's my HTACCESS:
Header set Access-Control-Allow-Origin *
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Allow-Headers "*"
Options -MultiViews
RewriteEngine On
RewriteRule ^badges/([0-9]+)/?$ badges.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Here's the URI script:
<?php
function getCurrentUri() {
$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
$uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
$uri = '/' . trim($uri, '/');
return $uri;
}
$base_url = getCurrentUri();
$routes = array();
$routes = explode('/', $base_url);
foreach($routes as $route) {
if(trim($route) != '')
array_push($routes, $route);
}
if ($base_url == "/" || $base_url == "/home") {
$page = "home";
} elseif ($base_url == "/about") {
$page = "about";
} elseif ($base_url == "/badges") {
$page = "badges";
}
?>
Here's my AJAX call:
$(document).ready(function() {
$.ajax({
url: '<?php echo $page; ?>.php',
success: function(content) {
$("#contfill").html(content);
history.pushState(null, '', '<?php echo $page; ?>');
homePageInit();
}
});
});
When www.domain.com/badges is used, it loads the page correctly as shown here:
The first badge's ID is 324. When www.domain.com/badges/324 is used, it loads the data correctly, but the page is blank as shown here:
Does anyone know why this would be?
EDIT
I added in a alert('$base_url'); to see what it would be. When using www.domain.com/badges, it shows as /badges. When using www.domain.com/badges/324 no alert pops up, so it seems that it's going directly to badges.php. Is that due to the HTACCESS?
SECOND EDIT
Here is my badges.php script:
<?php require('../panel/includes/config.php'); ?>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading bg-color-blue">
<h3 class="panel-title"><i class="fa fa-newspaper-o" aria-hidden="true"></i> Badge Guides</h3>
</div>
<div class="panel-body">
<p>
<img src="assets/images/1badge_guides.png" alt="Guides" class="img-responsive img-center">
<?php
if (isset($_GET["id"])) {
$id = $_GET["id"];
$newsQuery = $dbh->prepare("SELECT * FROM news WHERE id=:id");
$newsQuery->execute(array(":id"=>$id));
$newsQueryData = $newsQuery->fetch(PDO::FETCH_ASSOC);
?>
<br>
Tweet
<br>
<?php
echo htmlspecialchars_decode($newsQueryData['article']);
} else {
$reqInfo2 = $dbh->prepare("SELECT n.id,
n.image,
n.title,
n.category,
n.description,
n.article,
n.active,
n.level,
n.available,
n.author,
n.stamp,
c.cat_num,
c.cat_name,
a.active_num,
a.active_name,
av.avail_num,
av.avail_name,
l.level_num,
l.level_name
FROM news n
INNER JOIN news_cat c
ON n.category = c.cat_num
INNER JOIN active_cat a
ON n.active = a.active_num
INNER JOIN avail_cat av
ON n.available = av.avail_num
INNER JOIN level_cat l
ON n.level = l.level_num
WHERE n.category = 10 AND n.active = 1
ORDER BY n.stamp DESC");
$reqInfo2->execute();
?>
<p class="text-center">
<strong>BADGE GUIDES</strong>
</p>
<table class="table table-striped">
<thead>
<tr>
<th>Badge</th>
<th>Title</th>
<th>Description</th>
<th>Level</th>
<th>Availability</th>
</tr>
</thead>
<tbody>
<?php
while ($reqInfoData = $reqInfo2->fetch(PDO::FETCH_ASSOC)) {
?>
<tr class="bg-success">
<td><?php echo "<img src=\"{$reqInfoData['image']}\" class=\"img-responsive\">"; ?></td>
<td><?php echo "{$reqInfoData['title']}"; ?></td>
<td><?php echo $reqInfoData['description']; ?></td>
<td><?php echo $reqInfoData['level_name']; ?></td>
<td>
<?php
if ($reqInfoData['avail_name'] == "Available") {
echo "<span style=\"color: green;\">{$reqInfoData['avail_name']}</span>";
} else {
echo "<span style=\"color: red;\">{$reqInfoData['avail_name']}</span>";
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
?>
</p>
</div>
</div>
</div>
</div>
Here is the index.php page:
<?php
function getCurrentUri() {
$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
$uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
$uri = '/' . trim($uri, '/');
return $uri;
}
$base_url = getCurrentUri();
$routes = array();
$routes = explode('/', $base_url);
foreach($routes as $route) {
if(trim($route) != '')
array_push($routes, $route);
}
if ($base_url == "/" || $base_url == "/home") {
$page = "home";
} elseif ($base_url == "/about") {
$page = "about";
} elseif ($base_url == "/badges") {
$page = "badges";
}
require('../panel/includes/config.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Habbfinity</title>
<link rel="stylesheet" type="text/css" href="assets/css/normalize.css">
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/ie10-viewport-bug-workaround.css">
<link rel="stylesheet" type="text/css" href="assets/css/custom.css">
</head>
<body>
<div id="wrapper" class="container well">
<header>
<section id="brand" class="row">
<div class="col-md-8">
<img src="assets/images/habbfinitylogo.png" alt="Habbfinity" class="img-responsive img-center">
</div>
<div class="col-md-4">
<div class="panel panel-default radpan">
<div class="panel-body">
<?php
date_default_timezone_set('Europe/London');
$timecheck = date("H:00");
$timecheckwhour = strtotime($timecheck) + 60*60;
$newtimecheck = date("H:00", $timecheckwhour);
$daycheck = date("N");
$djQuery = $dbh->prepare("SELECT * FROM timetable WHERE day=:day AND time=:time");
$djQuery->execute(array(":day"=>$daycheck, ":time"=>$timecheck));
$djQueryData = $djQuery->fetch(PDO::FETCH_ASSOC);
if (isset($djQueryData) || $djQueryData != "") {
$djQuery2 = $dbh->prepare("SELECT * FROM users WHERE djname=:dj");
$djQuery2->execute(array(":dj"=>$djQueryData['dj']));
$djQueryData2 = $djQuery2->fetch(PDO::FETCH_ASSOC);
}
$djQuery3 = $dbh->prepare("SELECT * FROM timetable WHERE day=:day AND time=:time");
$djQuery3->execute(array(":day"=>$daycheck, ":time"=>$newtimecheck));
$djQuery3Data = $djQuery3->fetch(PDO::FETCH_ASSOC);
if (isset($djQuery3Data) || $djQuery3Data != "") {
$djQuery4 = $dbh->prepare("SELECT * FROM users WHERE djname=:dj");
$djQuery4->execute(array(":dj"=>$djQuery3Data['dj']));
$djQueryData4 = $djQuery4->fetch(PDO::FETCH_ASSOC);
}
$djSays = $dbh->prepare("SELECT * FROM dj_says ORDER BY id DESC LIMIT 1");
$djSays->execute();
$djSaysData = $djSays->fetch(PDO::FETCH_ASSOC);
?>
<audio autoplay id="player">
<source src="http://procyon.shoutca.st:8930/stream" type="audio/mp4">
<source src="http://procyon.shoutca.st:8930/stream" type="audio/ogg">
</audio>
<form method="post">
<p class="text-center">
<button type="button" class="btn btn-trans" onclick="document.getElementById('player').play()"><i class="fa fa-play galaxy" aria-hidden="true"></i></button>
<button type="button" class="btn btn-trans" onclick="document.getElementById('player').pause()"><i class="fa fa-pause galaxy" aria-hidden="true"></i></button>
<button type="button" class="btn btn-trans" onclick="javascript:ajaxpage('requests.php', 'contfill');"><i class="fa fa-comment galaxy" aria-hidden="true"></i></button>
<button type="submit" class="btn btn-trans" value="like" name="like"><i class="fa fa-heart galaxy" aria-hidden="true"></i></button>
</p>
<p>
<div class="row">
<div class="col-md-3">
<img src="https://www.habbo.com/habbo-imaging/avatarimage?hb=image&user=augmented_Runes&headonly=0&direction=4&head_direction=2&action=wav&gesture=&size=m" class="img-responsive img-center">
</div>
<div class="col-md-9">
<i class="fa fa-music" aria-hidden="true"></i> <span id="cc_strinfo_song_Habbfinity00" class="cc_streaminfo"></span>
<br>
<i class="fa fa-headphones" aria-hidden="true"></i> <span id="cc_strinfo_listeners_Habbfinity00" class="cc_streaminfo"></span> Listeners
<br>
<i class="fa fa-user" aria-hidden="true"></i> <span id="cc_strinfo_title_Habbfinity00" class="cc_streaminfo"></span>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="marquee2">
<span><?php echo $djSaysData['message']; ?></span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12" style="margin-top: 20px;">
<input id="vol-control" class="myrange" type="range" min="0" max="100" step="1" oninput="SetVolume(this.value)" onchange="SetVolume(this.value)"></input>
</div>
</div>
</p>
</form>
<?php
if (isset($_POST['like']) && isset($djQueryData2['habbo']) && $djQueryData2['habbo'] != "") {
$dj = $djQueryData2['habbo'];
$ip = $_SERVER['REMOTE_ADDR'];
$cur_time = time();
$djLikes = $dbh->prepare("SELECT * FROM djlikes WHERE dj=:dj AND likedip=:ip");
$djLikes->execute(array(":dj"=>$dj, ":ip"=>$ip));
$djLikesData = $djLikes->fetch(PDO::FETCH_ASSOC);
if ($djLikesData['likedip'] != "") {
$lasttime = $djLikesData['lastliked'];
$diff = abs($cur_time - $lasttime);
if ($diff > 3600) {
$AddLikes = $dbh->prepare("UPDATE djlikes SET likes = likes + 1 WHERE likedip=:ip");
$AddLikes->execute(array(":ip"=>$ip));
echo "Thank you for liking the DJ!";
} else {
echo "Please wait an hour before liking the DJ again!";
}
} else {
$AddLikes = $dbh->prepare("INSERT INTO djlikes VALUES (:habbo, :time:, :ip, 1)");
$AddLikes->execute(array(":habbo"=>$djQueryData2['habbo'], ":time"=>$cur_time, ":ip"=>$ip));
echo "Thank you for liking the DJ!";
}
}
?>
</div>
<div class="radimageoverdiv"><i class="fa fa-rocket galaxyl" aria-hidden="true"></i></div>
</div>
</div>
</section>
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><i class="fa fa-home" aria-hidden="true"></i> HOME</li>
<li class="dropdown">
<i class="fa fa-info-circle" aria-hidden="true"></i> HABBFINITY <span class="caret"></span>
<ul class="dropdown-menu">
<li>About Us</li>
<li>Our Team</li>
<li>Contact Us</li>
<li>Site News</li>
<li>Follow Our Twitter!</li>
</ul>
</li>
<li class="dropdown">
<i class="fa fa-newspaper-o" aria-hidden="true"></i> QUEST <span class="caret"></span>
<ul class="dropdown-menu">
<li>Badge Guides</li>
<li>Wired Guides</li>
<li>News</li>
</ul>
</li>
<li class="dropdown">
<i class="fa fa-gamepad" aria-hidden="true"></i> EVENTS <span class="caret"></span>
<ul class="dropdown-menu">
<li>Events Timetable</li>
<li>How To Play</li>
</ul>
</li>
<li class="dropdown">
<i class="fa fa-headphones" aria-hidden="true"></i> RADIO <span class="caret"></span>
<ul class="dropdown-menu">
<li>Radio Timetable</li>
<li>Request Line</li>
</ul>
</li>
<li class="dropdown">
<i class="fa fa-star" aria-hidden="true"></i> GOODIES <span class="caret"></span>
<ul class="dropdown-menu">
<li>Habbo Imager</li>
</ul>
</li>
<li><i class="fa fa-comments" aria-hidden="true"></i> FORUM</li>
</ul>
</div>
</nav>
</header>
<div id="contfill">
</div>
<a id="back-to-top" href="#" class="btn btn-primary btn-lg back-to-top" role="button" title="Click to return on the top page" data-toggle="tooltip" data-placement="left"><span class="glyphicon glyphicon-chevron-up"></span></a>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="HabboImager">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Habbo Imager</h4>
</div>
<div class="modal-body">
<?php include 'imager.php'; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="assets/js/jquery-3.3.1.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/respond.min.js"></script>
<script src="assets/js/ie10-viewport-bug-workaround.js"></script>
<script src="imagerscript.js"></script>
<script language="javascript" type="text/javascript" src="https://procyon.shoutca.st/system/streaminfo.js"></script>
<script>
window.SetVolume = function(val) {
var player = document.getElementById('player');
player.volume = val / 100;
}
function homePageInit() {
$('[data-toggle="tooltip"]').tooltip();
$(window).scroll(function() {
if ($(this).scrollTop() > 50) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
$('#back-to-top').click(function() {
$('#back-to-top').tooltip('hide');
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
$('#back-to-top').tooltip('show');
var badgeUrl = 'http://habboo-a.akamaihd.net/c_images/album1584/';
$.getJSON( 'http://habboemotion.com/api/badge', function( badges ) {
$.each( badges.list, function( key, badge ) {
$('div#badges').append('<img src="'+badgeUrl+badge.code+'.gif" class="thumbnail aleft" alt="Badge" data-toggle="tooltip" data-placement="top" title="'+badge.name+' - '+badge.desc+'">');
return (key !== 11);
});
});
$.getScript('https://platform.twitter.com/widgets.js', function() {
});
$.getScript('http://habbfinity.ca/forum/external.php?type=js', function() {
var str = "";
for (x = 0; x < 4; x++) {
str += ""+threads[x].title+" <br>(Posted By: "+threads[x].poster+")<br><br />";
}
$("#habbfinity_forum").html(str);
console.log(str);
});
}
$(document).ready(function() {
$.ajax({
url: '<?php echo $page; ?>.php',
success: function(content) {
$("#contfill").html(content);
history.pushState(null, '', '<?php echo $page; ?>');
homePageInit();
}
});
$('#home').on("click", function(event) {
$.ajax({
url: 'home.php',
success: function(content) {
$("#contfill").html(content);
history.pushState(null, '', 'home');
homePageInit();
}
});
event.preventDefault();
});
$('#about').on("click", function(event) {
$.ajax({
url: 'about.php',
success: function(content) {
$("#contfill").html(content);
history.pushState(null, '', 'about');
homePageInit();
}
});
event.preventDefault();
});
$('#badges').on("click", function(event) {
$.ajax({
url: 'badges.php',
success: function(content) {
$("#contfill").html(content);
history.pushState(null, '', 'badges');
homePageInit();
}
});
event.preventDefault();
});
});
</script>
</body>
</html>
After discussing in chat, the solution was to remove the RewriteRule ^badges/([0-9]+)/?$ badges.php?id=$1 [L] from the htaccess. Any url that doesn't have a .php renders only the content portion of #contfill.
We then needed to modify the url the ajax uses in index.php, to convert the route from '/badges/324' to '/badges.php?id=324'
I'm trying to learn php and MYSQL through developing an eCommerce website. So far the experience with these new languages are really good, but I'm stuck on one of my ideas. I have managed to add the order details to my database, however it adds only a product at a time. Originally what I wanted to do is to add more than a product and store it in a database.
For an example let's say an user wants to buy 5 items. How can I store this into my database. With my current code this just add as a single product with the total of 5 products.(Even the quantity is not adding up).
I'm not sure whether my code is correct. Any suggestions on this is really appreciated. (Please feel free to modify code, it will be really helpful)
Following is the code I'm using to add orders to database.
<div class="col-md-12">
<h4 class="text-center">Paypal Intergration Goes Here.</h4>
<img src="./images/paywith_paypal.png" class="img-responsive center-block" alt="Pay With Paypal">
<?php
// Getting product details
$total = 0;
global $con;
$ip = getIp();
$sel_price = "SELECT * FROM zeus_limited.cart WHERE ip_address='$ip'";
$run_price = mysqli_query($con, $sel_price);
while($p_price=mysqli_fetch_array($run_price)){
$product_id = $p_price['cart_product_id'];
$product_price = "SELECT * FROM zeus_limited.product WHERE product_id='$product_id'";
$run_product_price = mysqli_query($con,$product_price);
while ($prod_price = mysqli_fetch_array($run_product_price)){
$product_price = array($prod_price['product_price']);
$product_id = $prod_price['product_id'];
$pro_name = $prod_price['product_title'];
$values = array_sum($product_price);
$total +=$values;
}
}
// Getting Quantity from cart
$get_quantity = "SELECT * FROM zeus_limited.cart WHERE cart_product_id='$product_id'";
$show_quantity = mysqli_query($con, $get_quantity);
$row_qty = mysqli_fetch_array($show_quantity);
$quantity = $row_qty['quantity'];
if($quantity == 0){
$quantity = 1;
}
else {
$quantity = $quantity;
$total = $total * $quantity;
}
// Getting Customer details
$user = $_SESSION['customer_email'];
$get_customer = "SELECT * FROM zeus_limited.customer WHERE customer_email='$user'";
$show_customer = mysqli_query($con, $get_customer);
$row_c = mysqli_fetch_array($show_customer);
$customer_id = $row_c['customer_id'];
$customer_email = $row_c['customer_email'];
$customer_name = $row_c['customer_fname'];
$trx_id = mt_rand();
$currency = 'USD';
$invoice = mt_rand();
// Insert data to ORDER table
$add_order = "INSERT INTO zeus_limited.orders (order_product_id, order_customer_id, order_quantity, invoice_no, status, order_date) VALUES ('$product_id','$customer_id','$quantity','$invoice','in Progress',NOW())";
$run_order = mysqli_query($con, $add_order);
// Insert data to PAYMENT table
$add_payment = "INSERT INTO zeus_limited.payment (amount, payment_customer_id, payment_product_id, trx_id, payment_currency, payment_date) VALUES ('$total','$customer_id','$product_id','$trx_id','$currency',NOW())";
$run_payment = mysqli_query($con, $add_payment);
// Removing products from CART
$empty_cart = "DELETE FROM zeus_limited.cart";
$show_customerart = mysqli_query($con, $empty_cart);
if($total == $total){
echo "<div class='text-center'>";
echo "<h3>Welcome:" . $_SESSION['customer_email']. "<br>" . "Hooray! Your Payment was successful!</h3>";
echo "<a href='./customer/my_account.php'>Go to your Account</a><br>";
echo "</div>";
}
else {
echo "<div class='text-center'>";
echo "<h4>Welcome Guest, Payment process failed... Please try again</h4><br>";
echo "<a href='/shop_products.php'>Go to Back to shop</a>";
echo "</div>";
}
?>
</div>
I'm attaching the cart code as well.(if it's needed)
<?php
session_start();
require_once './includes/init.php';
require_once './functions/functions.php';
echo getCart();
?>
<!DOCTYPE html>
<html>
<head>
<title>Zeus Pvt. Ltd</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
<link rel="stylesheet" href="css/style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
<script src="js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="header">
<div class="container container-bg">
<div class="row">
<div class="col-md-4"><img src="images/logo.png" class="img-responsive" alt="Responsive image"></div>
<div class="col-md-5"></div>
<div class="col-md-3">
<div class="zeus_cart">
<div class="cart_bg">
<ul class="cart">
<i class="cart_icon"></i><p class="cart_desc"><?php getTotalCartPrice() ?><br><span class="yellow"><?php getTotalItems() ?></span></p>
<div class='clearfix'></div>
</ul>
<ul class="product_control_buttons">
<li><img src="images/close.png" alt=""/></li>
<li>Edit</li>
</ul>
<div class='clearfix'></div>
</div>
<ul class="quick_access">
<li class="view_cart">View Cart</li>
<li class="check">Checkout</li>
<div class='clearfix'></div>
</ul>
</div>
</div>
</div>
</div>
<div class="container container-bg">
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">Shop Products</li>
<li>My Account</li>
<li>Contact Us</li>
<li>
<?php
if(!isset($_SESSION['customer_email'])){
echo 'Login';
}
else {
echo 'Logout';
}
?>
</li>
<li class="welcome"><a>Welcome <?php echo getUsername(); ?></a></li>
</ul>
<form method="get" action="results.php" enctype="multipart/form-data" class="navbar-form navbar-right">
<div class="form-group search">
<input type="text" name="user_query" class="form-control" placeholder="Search Products">
</div>
<button type="submit" class="btn btn-default btn-search"></button>
</form>
</div>
</div>
</div>
</nav>
</div>
<div class="main">
<div class="container container-bg">
<div class="row">
<div class="col-md-12">
<div class="shoppingcart-title">
<h4 class="text-center sidebar-main-menu">Shopping Cart</h4>
<div class="table-responsive">
<form action="" method="POST" enctype="multipart/form-data">
<table class="table">
<thead>
<tr>
<th>Product No.</th>
<th>Product(s)</th>
<th>Name</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Sub Total</th>
<th>Remove</th>
</tr>
</thead>
</tbody>
<?php
global $con;
$total = 0;
$ip = getIp();
$select_price = "SELECT * FROM zeus_limited.cart WHERE zeus_limited.cart.ip_address='$ip'";
$run_price = mysqli_query($con, $select_price);
while ($product_price = mysqli_fetch_array($run_price)) {
$product_id = $product_price['cart_product_id'];
$product_quantity = $product_price['quantity'];
$product_price = "SELECT * FROM zeus_limited.product WHERE zeus_limited.product.product_id ='$product_id'";
$run_product_price = mysqli_query($con, $product_price);
while ($product_new_price = mysqli_fetch_array($run_product_price)) {
$product_price = array($product_new_price['product_price']);
$product_id = $product_new_price['product_id'];
$product_image = $product_new_price['product_image_carousel'];
$product_title = $product_new_price['product_title'];
$unit_product_price = $product_new_price['product_price'];
$values = array_sum($product_price);
$total += $values * $product_quantity;
?>
<tr>
<td><?php echo $product_id; ?></td>
<td><img src="images/products/<?php echo $product_image; ?>" </td>
<td><?php echo $product_title; ?></td>
<td><input id="" type="text" name="quantity[<?php echo $product_id; ?>]" size="5" value="<?php echo $product_quantity; ?>" style="text-align:center;"/>
<input type="hidden" name="product_id[<?php echo $product_id; ?>]" value="<?php echo $product_id; ?>"
</td>
<!--Updating the quantity-->
<?php
$ip = getIp();
if (isset($_POST['update_cart'])){
foreach ($_POST['product_id'] as $pid => $id) {
$product_id = $id;
$product_quantity = $_POST['quantity'][$pid];
$update_products = "UPDATE zeus_limited.cart SET quantity = '$product_quantity' WHERE cart_product_id = '$product_id' AND ip_address = '$ip';";
$run_update = mysqli_query($con, $update_products);
}
if($update_products){
echo "<script>window.open('cart.php','_self')</script>";
}
}
?>
<td><?php echo 'Rs '. $unit_product_price; ?></td>
<td><?php echo 'Rs '.$unit_product_price * $product_quantity ?></td>
<td><input type="checkbox" name="remove[]" value="<?php echo $product_id; ?>"/></td>
</tr>
</tbody>
<?php } } ?>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th>Grand Total: </th>
<th><?php echo 'Rs '. $total ?></th>
<th></th>
</tr>
</thead>
</table>
<div class="cart_buttons">
<input type="submit" name="update_cart" value="Update Cart"/>
<input type="submit" name="continue_shopping" value="Continue Shopping"/>
<input type="submit" name="checkout" value="Checkout"/>
<?php if (isset($_POST['checkout'])){echo "<script>window.open('checkout.php','_self')</script>"; } ?>
</div>
</form>
<?php
global $con;
$ip = getIp();
if (isset($_POST['update_cart'])){
foreach ($_POST['remove'] as $remove_id) {
$delete_product = "DELETE FROM zeus_limited.cart WHERE cart_product_id='$remove_id' AND ip_address='$ip'";
$run_delete = mysqli_query($con, $delete_product);
if($run_delete){
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
if (isset($_POST['continue_shopping'])){
echo "<script>window.open('shop_products.php','_self')</script>";
}
?>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<div class="row">
<div class="col-md-4 footer-grid">
<h3>Menu</h3>
<ul class="list1">
<li>Home</li>
<li>Shop Products</li>
<li>My Account</li>
<li>Contact Us</li>
<li>Login</li>
</ul>
</div>
<div class="col-md-4 footer-grid">
<h3>Your Account</h3>
<ul class="list1">
<li>My Orders</li>
<li>Edit Account</li>
<li>Change Password</li>
<li>Delete Account</li>
<li>My Cart</li>
</ul>
</div>
<div class="col-md-4 footer-grid">
<h3>About Us</h3>
<p class="footer_desc">Zeus is a pharmacy focused on providing patients with what they need and deserve - exceptional pharmacy care. It is our responsibility and passion to care for your medication needs.</p>
<p class="f_text"><span class="fa fa-phone" aria-hidden="true"></span> Phone: +081 123 45 67</p>
<p class="email"><span class="fa fa-envelope" aria-hidden="true"></span> Email: <span>info#zeuspharmacy.com</span></p>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
</div>
<div class="footer-bottom">
<div class="container">
<div class="row">
<div class="col-md-12 footer-grid-bottom">
<div class="copyrights">
<p>© 2017 Zeus Pharmacy. Made with <span class="fa fa-heart" aria-hidden="true"></span> by Dilum Tharaka</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
order table structure image
payment table structure image
Above are the table structures I'm using. Thanks in advance
How do I send to multiple recipients in php?
I only have one input field for the user to input all the recipients. The code already has a javascript which creates tags and autofill. The code only sends to the first input.
Here is the code:
<?php
error_reporting(0);
session_start();
include_once 'config.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM user WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
$deptm = mysql_query("SELECT * FROM departments WHERE dep_ID = ".$userRow['department_id']."");
$deptment = mysql_fetch_array($deptm);
if(isset($_POST['send-btn']))
{
$recipient = $_POST['TO'];
$check = mysql_query("SELECT * FROM user WHERE faculty_number='$recipient'");
$rec = mysql_fetch_array($check);
if($userRow['position'] == 'Department Head')
{
if($rec['position'] != 'Dean' && $rec['position'] != 'Faculty Secretary')
{
$subject = $_POST['subject'];
$message = $_POST['message'];
$indicator = $_POST['indicator'];
$counter = $_POST['typ_cnt'];
$date = date('M-j');
/*$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$recipient=$_POST['department'][$i];*/
if($del=mysql_query("INSERT INTO memo(memo_date, iso, memo_subject, content, memo_sender) VALUES ('$date', 'UST:".$indicator." - ".$counter."/AY 2015-2016', '$subject','$message','".$userRow['faculty_number']."')"))
{
$getID = mysql_query("SELECT * FROM memo ORDER BY memo_ID DESC LIMIT 1");
$id = mysql_fetch_array($getID);
if($recipient=mysql_query("INSERT INTO recipients(id,type,iso,memo_sender,recipient_num,read_status,read_timestamp,acknowledgement,ack_timestamp,delete_status) VALUES ('".$id['memo_ID']."','memo','UST:".$indicator." - ".$counter."/AY 2015-2016','".$userRow['faculty_number']."', '$recipient', 'unread', '---', 'Not Acknowledged', '---', 'active')"))
{
?>
<script>alert('Memo Sent');</script>
<?php
}
else{
?>
<script>alert('Failed');</script>
<?php
}
}
else{
?>
<script>alert('Failed');</script>
<?php
}
//}
}else{
?>
<script>alert('Your recipient is not allowed');</script>
<?php
}
}else if($userRow['position'] == 'Dean')
{
$subject = $_POST['subject'];
$message = $_POST['message'];
$indicator = $_POST['indicator'];
$counter = $_POST['typ_cnt'];
$date = date('M-j');
/*$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$recipient=$_POST['department'][$i];*/
if($del=mysql_query("INSERT INTO memo(memo_date, iso, memo_subject, content, memo_sender) VALUES ('$date', 'UST:".$indicator." - ".$counter."/AY 2015-2016', '$subject','$message','".$userRow['faculty_number']."')"))
{
$getID = mysql_query("SELECT * FROM memo ORDER BY memo_ID DESC LIMIT 1");
$id = mysql_fetch_array($getID);
if($recipient=mysql_query("INSERT INTO recipients(id,type,iso,memo_sender,recipient_num,read_status,read_timestamp,acknowledgement,ack_timestamp,delete_status) VALUES ('".$id['memo_ID']."','memo','UST:".$indicator." - ".$counter."/AY 2015-2016','".$userRow['faculty_number']."', '$recipient', 'unread', '---', 'Not Acknowledged', '---', 'active')"))
{
?>
<script>alert('Memo Sent');</script>
<?php
}
else{
?>
<script>alert('Failed');</script>
<?php
}
}
else{
?>
<script>alert('Failed');</script>
<?php
}
//}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<title>Welcome - <?php echo $userRow['position']; ?></title>
<!-- Bootstrap Core CSS -->
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel=
"stylesheet"><!-- MetisMenu CSS -->
<link href="bower_components/metisMenu/dist/metisMenu.min.css" rel=
"stylesheet"><!-- Timeline CSS -->
<link href="dist/css/timeline.css" rel="stylesheet"><!-- Custom CSS -->
<link href="dist/css/sb-admin-2.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="bower_components/morrisjs/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="bower_components/font-awesome/css/font-awesome.min.css" rel=
"stylesheet" type="text/css">
<!-- Bootstrap styling for Typeahead -->
<link href="dist/css/tokenfield-typeahead.css" type="text/css" rel="stylesheet">
<!-- Tokenfield CSS -->
<link href="dist/css/bootstrap-tokenfield.css" type="text/css" rel="stylesheet">
<!-- Docs CSS -->
<link href="docs-assets/css/pygments-manni.css" type="text/css" rel="stylesheet">
<link href="docs-assets/css/docs.css" type="text/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="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]-->
<script src="sendmemo.js" type="text/javascript"></script>
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('department[]');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-static-top" style=
"margin-bottom: 0">
<div class="navbar-header">
<button class="navbar-toggle" data-target=".navbar-collapse"
data-toggle="collapse" type="button"><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">UNIVERSITY OF SANTO TOMAS - FACULTY OF MEDICINE
DOCUMENT MANAGEMENT SYSTEM</a>
</div>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href=
"#"><i class="fa fa-bell fa-fw"></i> <i class=
"fa fa-caret-down"></i></a>
<ul class="dropdown-menu dropdown-alerts">
<li>
<a href="#">
<div>
<i class="fa fa-envelope-o fa-fw"></i> New
Message <span class=
"pull-right text-muted small">4 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-envelope fa-fw"></i> New
Message <span class=
"pull-right text-muted small">12 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-envelope fa-fw"></i> New
Message <span class=
"pull-right text-muted small">4 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-tasks fa-fw"></i> New Message
<span class="pull-right text-muted small">4
minutes ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-upload fa-fw"></i> Server
Rebooted <span class=
"pull-right text-muted small">4 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a class="text-center" href="#"><strong>See All
Notifications</strong> <i class=
"fa fa-angle-right"></i></a>
</li>
</ul>
<!-- /.dropdown-alerts -->
</li>
<!-- /.dropdown -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href=
""><i class="fa fa-user"></i>
<?php echo $userRow['first_name'];?> <?php echo $userRow['middle_name'];?> <?php echo $userRow['last_name'];?>
<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a><i class="fa fa-fw fa-user"></i>
<?php echo $userRow['position'];?></a>
</li>
<li class="divider">
</li>
<li>
<a href="changepass.php"><i class=
"fa fa-fw fa-wrench"></i> Change Password</a>
</li>
<li class="divider">
</li>
<li>
<a href="logout.php?logout"><i class=
"fa fa-fw fa-power-off"></i> Log Out</a>
</li>
</ul>
</li>
<!-- /.dropdown -->
</ul>
<div class="navbar-default sidebar">
<div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu">
<li>
<a href="<?php echo $_SESSION['home']?>"><i class=
"fa fa-home fa-fw"></i> Home</a>
</li>
<li>
<a href="sendmemo.php"><i class=
"fa fa-envelope-o fa-fw"></i> Send Memo</a>
</li>
<li>
<a href="index.html"><i class=
"fa fa-bar-chart-o fa-fw"></i> Reports<span class=
"fa arrow"></span></a>
<ul class="nav nav-second-level">
<li>
<a href="reports.php">List of
Acknowledgement</a>
</li>
<li>
<a href="index.html">Semestral Compliance
Report</a>
</li>
</ul>
<!-- /.nav-second-level -->
</li>
<li>
<a href="calendar.php"><i class=
"fa fa-table fa-fw"></i> Calendar</a>
</li>
<li>
<a href="inbox.php"><i class=
"fa fa-inbox fa-fw"></i> Inbox</a>
</li>
<li>
<a href="sent.php"><i class=
"fa fa-send-o fa-fw"></i> Sent</a>
</li>
<li>
<a href="allfiles.php"><i class=
"fa fa-files-o fa-fw"></i> All Files</a>
</li>
<?php
if($userRow['position'] = 'Dean' && $userRow['position'] = 'Faculty Secretary')
{ ?>
<li>
<i class="fa fa-folder fa-fw"></i> Folders
</li>
<?php
}else if($userRow['position'] = 'Department Head')
{ ?>
<li>
<i class="fa fa-folder fa-fw"></i> Folders
</li>
<?php
}else if($userRow['position'] = 'Faculty')
{ ?>
<li>
<i class="fa fa-folder fa-fw"></i> Folders
</li>
<?php
}
?>
<li>
<a href="upload.php"><i class=
"fa fa-upload fa-fw"></i> Upload Document</a>
</li>
</ul>
</div>
<!-- /.sidebar-collapse -->
</div>
<!-- /.navbar-static-side -->
</nav>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h2 class="text-center">Send Memo</h2>
<ul class="nav nav-tabs nav-justified">
<li class="active"><a data-toggle="tab" href="#memo">Memo</a></li>
<li><a data-toggle="tab" href="#letter">Letter</a></li>
</ul>
<?php
switch($userRow['position'])
{
case 'Dean': $ind="A001-001";
break;
case 'Faculty Secretary': $ind="A002-002";
break;
case 'Department Head': $ind="A003-003";
break;
}
$result=mysql_query("SELECT count(*) as total from recipients WHERE memo_sender=".$userRow['faculty_number']);
$cntr=mysql_fetch_assoc($result);
$cnt = $cntr['total']+1;
$curYr = date('Y');
?>
<div class="tab-content">
<div id="memo" class="tab-pane fade in active">
<form method="post">
<div class="form-inline" role="form" ><br>
<label>ISO:</label>
<div class="form-group">
<label>UST:</label>
<input class="form-control" name="indicator" value="<?php echo $ind;?>" style="width:90px;"
type="text">
</div>
<div class="form-group">
<label>-</label>
<input type="text" class="form-control" name="typ_cnt" value="ME<?php echo $cnt;?>" style="width:60px;">
<label>/AY <?php echo $curYr;?> - <?php echo date('Y',strtotime('+1 year'));?> </label>
</div>
</div><br>
<div class="form-group">
<label>TO:</label>
<div class="input-group">
<input name="TO" type="textbox" class="form-control" id="tokenfield-typeahead" value="
<?php
if(isset($_POST['select-btn']))
{
$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$del_id=$_POST['department'][$i];
echo $del_id.",";
}
}
?> "/>
<span class="input-group-btn">
<button class="btn btn-warning" type="button" value="Departments" data-toggle="modal" data-target="#myModal">Department</button>
</span>
</div>
</div>
<div class="form-group">
<label for="subj">SUBJECT:</label>
<input class="form-control" name="subject"
type="text">
</div>
<br>
<div class="form-group">
<label for="message">Message:</label>
<textarea class="form-control" name="message" rows="10"></textarea>
</div>
<button type="submit" name="send-btn" class="btn btn-warning">Send</button>
</form>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Departments</h4>
</div>
<div class="modal-body">
<form method="post" action="sendmemo.php">
<div class="form-group">
<?php
$deptlist = mysql_query("SELECT * FROM departments");
while($dept = mysql_fetch_array($deptlist))
{
echo "<div class='checkbox'>";
echo "<label>";
echo "<input type='checkbox' name='department[]' value='".$dept['department_name']."' >" . $dept['department_name'];
echo "</label>";
echo "</div>";
}
?>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="select-btn" class="btn btn-warning">Select</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div id="letter" class="tab-pane fade">
<form method="post">
<div class="form-inline" role="form" ><br>
<label>ISO:</label>
<div class="form-group">
<label>UST:</label>
<input class="form-control" name="indicator" value="<?php echo $ind;?>" style="width:90px;"
type="text">
</div>
<div class="form-group">
<label>-</label>
<input type="text" class="form-control" name="typ_cnt" value="ME<?php echo $cnt;?>" style="width:60px;">
<label>/AY <?php echo $curYr;?> - <?php echo date('Y',strtotime('+1 year'));?> </label>
</div>
</div><br>
<div class="form-group">
<label>TO:</label>
<div class="input-group">
<input name="TO" type="textbox" class="form-control">
<span class="input-group-btn">
<button class="btn btn-warning" type="button" value="Departments" data-toggle="modal" data-target="#myModal">Department</button>
</span>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Departments</h4>
</div>
<div class="modal-body">
<div class="form-group">
<?php
$deptlist = mysql_query("SELECT * FROM departments");
while($dept = mysql_fetch_array($deptlist))
{
$dept_head = mysql_query("SELECT faculty_number FROM user WHERE position='Department Head' AND department_id='".$dept['dep_ID']."'");
echo "<div class='checkbox'>";
echo "<label>";
echo "<input type='checkbox' name='department[]' value='$dept_head' >" . $dept['department_name'];
echo "</label>";
echo "</div>";
}
?>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-warning" data-dismiss="modal">Select</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="subj">SUBJECT:</label>
<input class="form-control" name="subject" type="text">
</div>
<br>
<div class="form-group">
<label for="message">Message:</label>
<textarea class="form-control" name="message" rows="10"></textarea>
</div>
<button type="submit" name="send-btn" class="btn btn-danger">Send</button>
</form>
</div>
</div>
</div>
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="bower_components/jquery/dist/jquery.min.js"></script> <!-- Bootstrap Core JavaScript -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <!-- Metis Menu Plugin JavaScript -->
<script src="bower_components/metisMenu/dist/metisMenu.min.js"></script> <!-- Custom Theme JavaScript -->
<script src="dist/js/sb-admin-2.js"></script>
<script type="text/javascript" src="jquery-ui/jquery-1.9.1.js"></script>
<script type="text/javascript" src="jquery-ui/jquery-ui.js"></script>
<script type="text/javascript" src="dist/bootstrap-tokenfield.js" charset="UTF-8"></script>
<script type="text/javascript" src="docs-assets/js/scrollspy.js" charset="UTF-8"></script>
<script type="text/javascript" src="docs-assets/js/affix.js" charset="UTF-8"></script>
<script type="text/javascript" src="docs-assets/js/typeahead.bundle.min.js" charset="UTF-8"></script>
<script>
var engine = new Bloodhound({
<!--local: [{value: 'red'}, {value: 'blue'}, {value: 'green'} , {value: 'yellow'}, {value: 'violet'}, {value: 'brown'}, {value: 'purple'}, {value: 'black'}, {value: 'white'}, {value: 'jerome'}],
local: [<?php $suggest = mysql_query("SELECT * FROM user");
while($info = mysql_fetch_array($suggest))
{
echo "{value: '".$info['faculty_number']." (".$info['last_name'].", ".$info['first_name'].")'},";
}
?>],
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
engine.initialize();
$('#tokenfield-typeahead').tokenfield({
typeahead: [null, { source: engine.ttAdapter() }]
});
</script>
</body>
</html>
Basically, what you should do to send to a couple recipients is:
$message = "Email Body goes here";
$to = $recepient1.",".$recepient2.",".$recepient3;
$subject = 'Some Subject';
$from = $sender_email;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
mail($to, $subject, $message, $headers);
You didn't post your (full) email code, only a part that puts some data in a database.
Look at this post:
PHP form send email to multiple recipients
If you can't implement it yourself, update your question with your full email code so i can do it for you.
Edit:
I implemented this snippet; you have to enter the recipients with a , (comma + space) between them in the old html form field;
<?php
$recipient = "recipienta, recipientb";
$recipients = explode(", ",$recipient);
foreach ($recipients as $recipient) {
echo $recipient;
}
?>
Here is the relevant part of your code with the snippet implemented, i don't have all your dependencies so i couldn't test it but it should work, if it doesn't just let me know your problem and i'll fix it <3;
<?php
error_reporting(0);
session_start();
include_once 'config.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM user WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
$deptm = mysql_query("SELECT * FROM departments WHERE dep_ID = ".$userRow['department_id']."");
$deptment = mysql_fetch_array($deptm);
if(isset($_POST['send-btn']))
{
$recipient = $_POST['TO'];
$recipients = explode(", ",$recipient);
foreach ($recipients as $recipient) {
$check = mysql_query("SELECT * FROM user WHERE faculty_number='$recipient'");
$rec = mysql_fetch_array($check);
if($userRow['position'] == 'Department Head')
{
if($rec['position'] != 'Dean' && $rec['position'] != 'Faculty Secretary')
{
$subject = $_POST['subject'];
$message = $_POST['message'];
$indicator = $_POST['indicator'];
$counter = $_POST['typ_cnt'];
$date = date('M-j');
/*$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$recipient=$_POST['department'][$i];*/
if($del=mysql_query("INSERT INTO memo(memo_date, iso, memo_subject, content, memo_sender) VALUES ('$date', 'UST:".$indicator." - ".$counter."/AY 2015-2016', '$subject','$message','".$userRow['faculty_number']."')"))
{
$getID = mysql_query("SELECT * FROM memo ORDER BY memo_ID DESC LIMIT 1");
$id = mysql_fetch_array($getID);
if($recipient=mysql_query("INSERT INTO recipients(id,type,iso,memo_sender,recipient_num,read_status,read_timestamp,acknowledgement,ack_timestamp,delete_status) VALUES ('".$id['memo_ID']."','memo','UST:".$indicator." - ".$counter."/AY 2015-2016','".$userRow['faculty_number']."', '$recipient', 'unread', '---', 'Not Acknowledged', '---', 'active')"))
{
?>
<script>alert('Memo Sent');</script>
<?php
}
else{
?>
<script>alert('Failed');</script>
<?php
}
}
else{
?>
<script>alert('Failed');</script>
<?php
}
//}
}else{
?>
<script>alert('Your recipient is not allowed');</script>
<?php
}
}else if($userRow['position'] == 'Dean')
{
$subject = $_POST['subject'];
$message = $_POST['message'];
$indicator = $_POST['indicator'];
$counter = $_POST['typ_cnt'];
$date = date('M-j');
/*$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$recipient=$_POST['department'][$i];*/
if($del=mysql_query("INSERT INTO memo(memo_date, iso, memo_subject, content, memo_sender) VALUES ('$date', 'UST:".$indicator." - ".$counter."/AY 2015-2016', '$subject','$message','".$userRow['faculty_number']."')"))
{
$getID = mysql_query("SELECT * FROM memo ORDER BY memo_ID DESC LIMIT 1");
$id = mysql_fetch_array($getID);
if($recipient=mysql_query("INSERT INTO recipients(id,type,iso,memo_sender,recipient_num,read_status,read_timestamp,acknowledgement,ack_timestamp,delete_status) VALUES ('".$id['memo_ID']."','memo','UST:".$indicator." - ".$counter."/AY 2015-2016','".$userRow['faculty_number']."', '$recipient', 'unread', '---', 'Not Acknowledged', '---', 'active')"))
{
?>
<script>alert('Memo Sent');</script>
<?php
}
else{
?>
<script>alert('Failed');</script>
<?php
}
}
else{
?>
<script>alert('Failed');</script>
<?php
}
//}
}
}
}
?>