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
}
//}
}
}
}
?>
Related
I am a beginner and trying to follow some tutorial videos for my school project. I am stuck when the data not inserted into the database. I double-check the code to tutorial and nothing wrong. There's no error message or notification too. I really appreciate your help.
action.php
<!--action.php-->
<?php
require 'config.php';
if(isset($_POST['pid'])){
$pid = $_POST['pid'];
$pname = $_POST['pname'];
$pprice = $_POST['pprice'];
$pimage = $_POST['pimage'];
$pcode = $_POST['pcode'];
$pqty = 1;
$stmt = $conn->prepare("SELECT product_code FROM cart WHERE product_code=?");
$stmt->bind_param("s",$pcode);
$stmt->execute();
$res = $stmt->get_result();
$r = $res->fetch_assoc();
$code = $r['product_code'];
if(!$code){
$query = $conn->prepare("INSERT INTO cart (product_name,product_price,product_image,qty,total_price,produk_code) VALUES (?,?,?,?,?,?)");
$query->bind_param("sssiss",$pname,$pprice,$pimage,$pqty,$pprice,$pcode);
$query->execute();
echo '<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Item added to cart!</strong>
</div>';
}
else{
echo '<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Item already added to your cart!</strong>
</div>';
}
}
?>
index.php
<!--index.php-->
<!DOCTYPE html>
<html>
<head>
<title>Map Store</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://kit.fontawesome.com/fc847822ba.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/bootstrap.min.css" >
<link rel="stylesheet" type="text/css" href="fontawesome/css/all.min.css"/>
</head>
<body>
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="index.php">Map Store</a>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="index.php">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Category</a>
</li>
<li class="nav-item">
<a class="nav-link" href="cart.php">Checkout</a>
</li>
<li class="nav-item">
<a class="nav-link" href="cart.php"><i class="fas fa-shopping-cart text-white"> <span id="cart-item" class="badge badge-danger">0</span> </i></a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row mt-2">
<div id="message">
</div>
<?php
include 'config.php';
$stmt = $conn->prepare("SELECT * FROM product");
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()):
?>
<div class="col-lg-3">
<div class="card-deck">
<div class="card p-2 border-secondary mb-2">
<img src="<?= $row['product_image'] ?>" class="card-img-top" height="250">
<div class="card-body p-1">
<h4 class="card-title text-center text-info"><?= $row['product_name']?></h4>
<h5 class="card-text text-center text-danger"><?= number_format($row
['product_price'],2) ?>/-</h5>
</div>
<div class="card-footer p-1">
<form action="#" class="form-submit">
<input type="hidden" class="pid" value="<?= $row['id']?>">
<input type="hidden" class="pname" value="<?= $row['product_name']?>">
<input type="hidden" class="pprice" value="<?= $row['product_price']?>">
<input type="hidden" class="pimage" value="<?= $row['product_image']?>">
<input type="hidden" class="pcode" value="<?= $row['product_code']?>">
<button class="btn btn-info btn-block addItemBtn"><i class="fas fa-cart-plus "></i>Add to cart</button>
</form>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".addItemBtn").click(function(e){
e.preventDefault();
var $form = $(this).closest(".form-submit");
var pid = $form.find(".pid").val();
var pname = $form.find(".pname").val();
var pprice = $form.find(".pprice").val();
var pimage = $form.find(".pimage").val();
var pcode = $form.find(".pcode").val();
$.ajax({
url: 'action.php',
method: 'post',
data: {pid:pid,pname:pname,pprice:pprice,pimage:pimage,pcode:pcode},
success:function(response){
$("message").html(response);
}
});
});
});
</script>
</body>
</html>
config.php
<!--config.php-->
<?php
$conn = new mysqli("localhost","root","","checkout_system");
if($conn->connect_error){
die("Connection Failed!".$conn->connect_error);
}
?>
sorry i am new here and this my first post
The HTML elements in your form must have a name attribute to be available in $_POST, you set only a class :
<input type="hidden" name="pid" class="pid" value="<?= $row['id']?>">
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>
In my project im getting such kind of error when im trying to redirect to another page when the person submit the contact form then it should redirect to some other page but im getting such kind of error. the error what im getting is this
warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs\grade\header.php:89) in
C:\xampp\htdocs\grade\contact.php on line 64
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>SAMSON SOLAR ENERGY</title>
<!-- Meta tag Keywords -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta name="keywords" content="Grade Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
<script type="application/x-javascript">
addEventListener("load", function () {
setTimeout(hideURLbar, 0);
}, false);
function hideURLbar() {
window.scrollTo(0, 1);
}
</script>
<!--// Meta tag Keywords -->
<!-- css files -->
<link rel="stylesheet" href="css/bootstrap.css"> <!-- Bootstrap-Core-CSS -->
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" /> <!-- Style-CSS -->
<link rel="stylesheet" href="css/fontawesome-all.css"> <!-- Font-Awesome-Icons-CSS -->
<!-- //css files -->
<!----->
<link rel="stylesheet" href="css/flexslider.css" type="text/css" media="all" /><!-- for testimonials -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!--web font-->
<link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese" rel="stylesheet">
<!--//web font-->
</head>
<body>
<!-- header -->
<header>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light">
<a class="navbar-brand" href="index.html">
<span class="fa fa-strikethrough"></span> SAMSON SOLAR
</a>
<button class="navbar-toggler ml-md-auto" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mx-auto text-center">
<li class="nav-item active mr-lg-3">
<a class="nav-link" href="index.php">Home<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item mr-lg-3">
<a class="nav-link" href="about.php">about</a>
</li>
<li class="nav-item mr-lg-3">
<a class="nav-link" href="gallery.php">Gallery</a>
</li>
<li class="nav-item dropdown mr-lg-3">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Products</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="domestic.php">Domestic</a>
<a class="dropdown-item" href="commercial.php">Commercial</a>
<a class="dropdown-item" href="other.php">Other Products</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.php">contact</a>
</li>
</ul>
<div class="buttons">
<p><i class="fas mr-1 fa-phone"></i> +91 99161 67190</p>
</div>
</div>
</nav>
</div>
<div class="icon-bar">
<i class="fa fa-facebook"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-google"></i>
<i class="fa fa-linkedin"></i>
<i class="fa fa-youtube"></i>
</div>
</header>
<!-- //header -->
contact.php
<?php include 'header.php'; ?>
<!-- banner -->
<section class="inner-banner">
<div class="banner-layer">
<h1 class="text-center">Contact Page</h1>
</div>
</section>
<!-- //banner -->
<?php
include_once 'connect.php';
$nameErr = $emailErr = $contactErr = "";
$name = $email = $contact = $subject = "";
if (isset($_POST['submit']))
{
//Name
if (empty($_POST["name"])) {
$nameErr = "Please enter your Name";
}
else{
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Sorry Only letters are allowed";
}
}
//E-mail ID
if (empty($_POST["email"])) {
$emailErr = "Please enter your E-mail ID";
}
else{
$email = test_input($_POST["email"]);
// check if the entered Email-id is valid or not
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Please enter a valid E-mail ID";
}
}
//Contact Number
if (empty($_POST["phone"])) {
$contactErr = "Please enter your Contact Number";
}
else{
$contact = test_input($_POST["phone"]);
// check weather the contact number is valid or not
if (!preg_match("/^[0-9]+$/",$contact)) {
$contactErr = "Please enter Your 10 Digit mobile Number";
}
}
//Reason For contacting
if (!empty($_POST["subject"])) {
$subject = test_input($_POST["subject"]);
}
if($nameErr == "" && $emailErr == "" && $contactErr == ""){
$sql = "INSERT INTO contact(`ID`,`Name`, `Email`, `Contact_no` , `Reason`)
VALUES ('','".$name."', '".$email."', '".$contact."' , '".$subject."')";
if (mysqli_query($mysqli, $sql)) {
header("location:contact_success.php");
exit();
}
else{
echo "Error: " . $sql . "<br>" . mysqli_error($mysqli);
}
mysqli_close($mysqli);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!-- contact -->
<section class="contact py-5">
<div class="container">
<h2 class="heading mb-lg-5 mb-4">Contact Us</h2>
<div class="row contact-grids w3-agile-grid">
<div class="row col-md-6 col-sm-6 contact-grid1 w3-agile-grid">
<div class="col-3 text-center">
<i class="fa fa-commenting-o" aria-hidden="true"></i>
</div>
<div class="col-9 p-0">
<h4>Get In Touch</h4><br>
<p><b>Mobile:</b> +91 9916167190</p>
<p><b>E-mail:</b> abpaple#gmail.com</p>
</div>
</div>
<div class="row col-md-6 col-sm-6 mt-sm-0 mt-4 contact-grid1 w3-agile-grid">
<div class="col-3 text-center">
<i class="fa fa-map-marker" aria-hidden="true"></i>
</div>
<div class="col-9 p-0">
<h4>Visit Our Location</h4><br>
<p><b>SAMSON SOLAR ENERGY</b></p>
<p>#02, K.E.Board Complex, Navalgund Road, Shivaji Circle</p>
<p>DHARWAD-580008, KARNATAKA, INDIA</p>
</div>
</div>
</div><br><br>
<div class="row">
<div class="col-lg-7 col-md-7 col-sm-12 col-xs-12">
<div class="gmap_canvas">
<iframe width="100%" height="475" id="gmap_canvas" src="https://maps.google.com/maps?q=SAMSON%20SOLAR%20ENERGY%20%20%2302%2C%20K.E.Board%20Complex%2C%20Navalgund%20Road%2C%20Shivaji%20Circle%20%20DHARWAD-580008%2C%20KARNATAKA%2C%20INDIA&t=&z=13&ie=UTF8&iwloc=&output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>
</div>
</div>
<div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
<h2 style="margin-bottom:15px">Write To Us</h2>
<form action="" method="post">
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Name" name="name" value="<?php if (isset($name)) echo $name; ?>">
<span style="color:red;"> <?php echo $nameErr;?></span>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Enter E-mail" name="email" value="<?php if (isset($email)) echo $email; ?>">
<span style="color:red;"> <?php echo $emailErr;?></span>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Contact Number" name="phone" value="<?php if (isset($contact)) echo $contact; ?>">
<span style="color:red;"> <?php echo $contactErr;?></span>
</div>
<div class="form-group">
<textarea class="form-control" rows="4" placeholder="Enter Reason For Contacting" name="subject"><?php if (isset($subject)) echo $subject; ?></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right" name="submit">Submit</button>
</form>
</div>
</div>
</div>
</section>
<!-- //contact -->
<?php include 'footer.php'; ?>
please can any one help me to solve my issue
There are lots of reason for the error: Cannot modify header information - headers already sent below are some of them:
print and echo statements will terminate the opportunity to send HTTP headers
<html> before any header() call.
Whitespace before <?php
Whitespace after ?>
Preceding error messages can also be a cause of this error.
If You want to check all reasons in detail then here is referenced stackoveflow answer
But for you the reason of this error is that, you have included Raw sections prior
to <?php code, you can not include html before php code.
In your code you are including header.php and <section> which is html, before php code therefor you are getting this error, so for solving it change your
contact.php file as below
<?php
include_once 'connect.php';
$nameErr = $emailErr = $contactErr = "";
$name = $email = $contact = $subject = "";
if (isset($_POST['submit']))
{
//Name
if (empty($_POST["name"])) {
$nameErr = "Please enter your Name";
}
else{
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Sorry Only letters are allowed";
}
}
//E-mail ID
if (empty($_POST["email"])) {
$emailErr = "Please enter your E-mail ID";
}
else{
$email = test_input($_POST["email"]);
// check if the entered Email-id is valid or not
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Please enter a valid E-mail ID";
}
}
//Contact Number
if (empty($_POST["phone"])) {
$contactErr = "Please enter your Contact Number";
}
else{
$contact = test_input($_POST["phone"]);
// check weather the contact number is valid or not
if (!preg_match("/^[0-9]+$/",$contact)) {
$contactErr = "Please enter Your 10 Digit mobile Number";
}
}
//Reason For contacting
if (!empty($_POST["subject"])) {
$subject = test_input($_POST["subject"]);
}
if($nameErr == "" && $emailErr == "" && $contactErr == ""){
$sql = "INSERT INTO contact(`ID`,`Name`, `Email`, `Contact_no` , `Reason`)
VALUES ('','".$name."', '".$email."', '".$contact."' , '".$subject."')";
if (mysqli_query($mysqli, $sql)) {
header("location:contact_success.php");
exit();
}
else{
echo "Error: " . $sql . "<br>" . mysqli_error($mysqli);
}
mysqli_close($mysqli);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php include 'header.php'; ?>
<!-- banner -->
<section class="inner-banner">
<div class="banner-layer">
<h1 class="text-center">Contact Page</h1>
</div>
</section>
<!-- //banner -->
<!-- contact -->
<section class="contact py-5">
<div class="container">
<h2 class="heading mb-lg-5 mb-4">Contact Us</h2>
<div class="row contact-grids w3-agile-grid">
<div class="row col-md-6 col-sm-6 contact-grid1 w3-agile-grid">
<div class="col-3 text-center">
<i class="fa fa-commenting-o" aria-hidden="true"></i>
</div>
<div class="col-9 p-0">
<h4>Get In Touch</h4><br>
<p><b>Mobile:</b> +91 9916167190</p>
<p><b>E-mail:</b> abpaple#gmail.com</p>
</div>
</div>
<div class="row col-md-6 col-sm-6 mt-sm-0 mt-4 contact-grid1 w3-agile-grid">
<div class="col-3 text-center">
<i class="fa fa-map-marker" aria-hidden="true"></i>
</div>
<div class="col-9 p-0">
<h4>Visit Our Location</h4><br>
<p><b>SAMSON SOLAR ENERGY</b></p>
<p>#02, K.E.Board Complex, Navalgund Road, Shivaji Circle</p>
<p>DHARWAD-580008, KARNATAKA, INDIA</p>
</div>
</div>
</div><br><br>
<div class="row">
<div class="col-lg-7 col-md-7 col-sm-12 col-xs-12">
<div class="gmap_canvas">
<iframe width="100%" height="475" id="gmap_canvas" src="https://maps.google.com/maps?q=SAMSON%20SOLAR%20ENERGY%20%20%2302%2C%20K.E.Board%20Complex%2C%20Navalgund%20Road%2C%20Shivaji%20Circle%20%20DHARWAD-580008%2C%20KARNATAKA%2C%20INDIA&t=&z=13&ie=UTF8&iwloc=&output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>
</div>
</div>
<div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
<h2 style="margin-bottom:15px">Write To Us</h2>
<form action="" method="post">
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Name" name="name" value="<?php if (isset($name)) echo $name; ?>">
<span style="color:red;"> <?php echo $nameErr;?></span>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Enter E-mail" name="email" value="<?php if (isset($email)) echo $email; ?>">
<span style="color:red;"> <?php echo $emailErr;?></span>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Contact Number" name="phone" value="<?php if (isset($contact)) echo $contact; ?>">
<span style="color:red;"> <?php echo $contactErr;?></span>
</div>
<div class="form-group">
<textarea class="form-control" rows="4" placeholder="Enter Reason For Contacting" name="subject"><?php if (isset($subject)) echo $subject; ?></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right" name="submit">Submit</button>
</form>
</div>
</div>
</div>
</section>
<!-- //contact -->
<?php include 'footer.php'; ?>
And if problem remains the same after changing file as above then try to separate html file contact.php and make new php process file like contact_process.php and add php processing code only in contact_process.php.
Instead of
if (mysqli_query($mysqli, $sql)) {
header("location:contact_success.php");
exit();
}
You could do this:
if (mysqli_query($mysqli, $sql)) {
echo "<script>window.location.href = 'contact_success.php';</script>";
exit();
}
May not be conventional but it should work.
currently I have a website with a basic login, I was just wondering how I would display a the name,skill and description of the unique user who is logged in.This is what I have done so far.I can only find articles on how to display data into table.This is the updated code:
<?php
include('session.php');
require 'config.php';
$sql = "SELECT * FROM profile";
$result = $conn->query($sql);
//echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="profile.css">
</head>
<body>
<ul>
<li>Home</li>
<li>PostJob</li>
<li>Find Job</li>
<li>How It Works</li>
<li>Notifications</li>
<li>Message</li>
<li>profile</li>
</ul>
<h1>Welcome To Bid4MyJob</h1>
<li>edit profile</li>
<div id="ProfilePage">
<div id="LeftCol">
<div id="Photo"></div>
<div id="ProfileOptions">
a
</div>
</div>
<div id="Info">
<p>
<strong>Name:<?php echo $row["name"]?></strong>
<!--<span>James</span>-->
</p>
<p>
<strong>Skill:<?php echo $row["skill"]?><</strong>
<!--span>James</span>-->
</p>
<!-- <p>
<strong>review:<?php /*echo $row["review"]*/?><</strong>
<span>james</span>
</p> -->
<p>
<strong>Description:<?php echo $row["description"]?><</strong>
<span>James</span>
</p>
<!--<p>
<strong>Name:</strong>
<span>james</span>
</p>-->
</div>
<!-- Needed because other elements inside ProfilePage have floats
<div style="clear:both"></div>-->
</div>
</body>
</html>
Picture of database table:
https://imgur.com/a/XYTLY
Session.php:
<?php
include('config.php');
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($conn,"select email_adress from customer where email_adress = '$user_check' ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['email_adress'];
if(!isset($_SESSION['login_user'])){
header("location:login.php");
}
?>
Login.php:
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($conn,$_POST['username']);
$mypassword = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['customer_id'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
$_SESSION['login_user'] = $myusername;
header("location: index2.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login | Bid4MyJob</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Bid4MyJob">
<meta name="author" content="James Wood">
<!-- CSS -->
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/main.css" rel="stylesheet" type="text/css">
<link href="assets/css/my-custom-styles.css" rel="stylesheet" type="text/css">
<!-- IE 9 Fallback-->
<!--[if IE 9]>
<link href="assets/css/ie.css" rel="stylesheet">
<![endif]-->
<!-- GOOGLE FONTS -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400italic,400,600,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:300,300italic,400italic,700,400,300' rel='stylesheet' type='text/css'>
<!-- FAVICONS -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/repute144x144.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/repute114x114.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/repute72x72.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/repute57x57.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<body>
<!-- WRAPPER -->
<div class="wrapper">
<!-- NAVBAR -->
<nav class="navbar navbar-default " role="navigation">
<div class="container">
<!-- TOPBAR -->
<div class="topbar">
<ul class="list-inline top-nav">
<li>
<div class="btn-group">
<button type="button" class="btn btn-link dropdown-toggle btn-xs" data-toggle="dropdown"><img src="assets/img/flags/United-Kingdom.png" alt="United Kingdom"> United Kingdom <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right country-selector" role="menu">
<li>
<img src="assets/img/flags/United-Kingdom.png" alt="United Kingdom"> United Kingdom
</li>
<li>
<img src="assets/img/flags/Japan.png" alt="Japan"> Japan
</li>
<li>
<img src="assets/img/flags/China.png" alt="China"> China
</li>
<li>
<img src="assets/img/flags/Germany.png" alt="Germany"> Germany
</li>
</ul>
</div>
</li>
<li>Help</li>
<li>Support</li>
</ul>
<div class="searchbox">
<form method="post">
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="search ...">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-search"></i></button>
</span>
</div>
</form>
</div>
</div>
<!-- END TOPBAR -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-nav">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.html" class="navbar-brand navbar-logo navbar-logo-bigger">
</a>
</div>
<!-- MAIN NAVIGATION -->
<div id="main-nav" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>
HOME
</li>
<li>
HOW IT WORKS
</li>
<li>
POST JOB
</li>
<li>
FIND JOB
</li>
<li>
SIGN UP
</li>
<li>
LOGIN
</li>
</ul>
</div>
<!-- END MAIN NAVIGATION -->
</div>
</nav>
<!-- END NAVBAR -->
<!-- BREADCRUMBS -->
<div class="page-header">
<div class="container">
<h1 class="page-title pull-left">Login</h1>
<ol class="breadcrumb">
<li>Home</li>
<li class="active">Login</li>
</ol>
</div>
</div>
<!-- END BREADCRUMBS -->
<!-- PAGE CONTENT -->
<div class="page-content">
<div class="col-md-6">
<!-- LOGIN FORM -->
<h2 class="section-heading">Login Form</h2>
<form class="form-horizontal" role="form" action = "" method = "post">
<div class="form-group">
<label for="username" class="control-label sr-only">Email</label>
<div class="col-sm-12">
<div class="input-group">
<input type="email" class="form-control" id="username" name = "username" placeholder="Email">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
</div>
</div>
</div>
<div class="form-group">
<label for="password" class="control-label sr-only">Password</label>
<div class="col-sm-12">
<div class="input-group">
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label class="fancy-checkbox">
<input type="checkbox">
<span>Remember me</span>
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> Sign in</button>
</div>
</div>
</form>
<br>
<p><em>Don't have an account yet?</em> <strong>Sign Up</strong>
<br>
<em>Forgot your password?</em> Recover Password</p>
<!-- END LOGIN FORM -->
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-md-6">
<!-- LOGIN FORM WITH LABEL -->
<!-- END LOGIN FORM WITH LABEL -->
</div>
<div class="col-md-6">
<!-- SIMPLE FORM -->
<!-- END SIMPLE FORM -->
</div>
</div>
<br>
<br>
<!-- INLINE FORM -->
<!-- END INLINE FORM -->
</div>
</div>
</div>
</div>
<!-- END PAGE CONTENT -->
<!-- FOOTER -->
<footer>
<div class="container">
<div class="row">
<div class="col-md-4">
<!-- COLUMN 1 -->
<h3 class="sr-only">ABOUT US</h3>
<img src="assets/img/logo/repute-logo-light.png" class="logo" alt="Repute">
<p>Proactively aggregate B2B initiatives before extensive channels. Monotonectally extend interactive methods of empowerment through excellent applications. Rapidiously synergize visionary products with sticky technology.</p>
<br>
<address class="margin-bottom-30px">
<ul class="list-unstyled">
<li>Unit 5, Block B Nesfield Road
<br/> Colchester, Essex CO4 3ZL 222222</li>
<li>Phone: 01206 588 000</li>
<li>Email: sales#universalwebdesign.co.uk</li>
</ul>
</address>
<!-- END COLUMN 1 -->
</div>
<div class="col-md-4">
<!-- COLUMN 2 -->
<h3 class="footer-heading">USEFUL LINKS</h3>
<div class="row margin-bottom-30px">
<div class="col-xs-6">
<ul class="list-unstyled footer-nav">
<li>About Us</li>
<li>News</li>
<li>Community</li>
<li>Career</li>
<li>Blog</li>
</ul>
</div>
<div class="col-xs-6">
<ul class="list-unstyled footer-nav">
<li>Press Kit</li>
<li>FAQ</li>
<li>Terms</li>
<li>Privacy Policy</li>
<li>Contact Us</li>
</ul>
</div>
</div>
<!-- END COLUMN 2 -->
</div>
<div class="col-md-4">
<!-- COLUMN 3 -->
<div class="newsletter">
<h3 class="footer-heading">NEWSLETTER</h3>
<p>Get the latest update from us by subscribing to our newsletter.</p>
<form class="newsletter-form" method="POST">
<div class="input-group input-group-lg">
<input type="email" class="form-control" name="email" placeholder="youremail#domain.com">
<span class="input-group-btn"><button class="btn btn-primary" type="button"><i class="fa fa-spinner fa-spin"></i><span>SUBSCRIBE</span></button>
</span>
</div>
<div class="alert"></div>
</form>
</div>
<div class="social-connect">
<h3 class="footer-heading">GET CONNECTED</h3>
<ul class="list-inline social-icons">
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-google-plus"></i></li>
<li><i class="fa fa-rss"></i></li>
</ul>
</div>
<!-- END COLUMN 3 -->
</div>
</div>
</div>
<!-- COPYRIGHT -->
<div class="text-center copyright">
©2018 Bid4MyJob. All Rights Reserved.
</div>
<!-- END COPYRIGHT -->
</footer>
<!-- END FOOTER -->
</div>
<!-- END WRAPPER -->
<!-- JAVASCRIPTS -->
<script src="assets/js/jquery-2.1.1.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/plugins/autohidingnavbar/jquery.bootstrap-autohidingnavbar.min.js"></script>
<script src="assets/js/repute-scripts.js"></script>
</body>
</html>
You need a field on Profile that links to the customer table (or viceversa).
email can be in both tables, then you can link to your $login_session
SELECT * FROM profile WHERE email = '$login_session' LIMIT 1
In this case, take care and do not let users to change their email (without verification they own it) and do not let create a new account with the same credentials as another one.
But as a good practice on DB, it is better to have profile_id on customer
session.php
$ses_sql = mysqli_query($conn,"select email_adress, profile_id from customer where email_adress = '$user_check' ");
index.php
$sql = "SELECT * FROM profile WHERE profile_id = $profile_id LIMIT 1";
BTW:
- Try to separate concerns, between database and presentation layer. You should read more about MVC.
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.