Update as of 23rd June 2015
The update query still not working. Took an advice from Rene Kross and made some code cleanup and stumbled upon a few part missing semicolons and etc however the update query are still not working.
Here's the adminUpdate.php
<?php
require 'Connect.php';
$staffID = null;
if ( !empty($_GET['staffID'])) {
$staffID = $_REQUEST['staffID'];
}
if ( null==$staffID ) {
header("Location: ManageAdministrator.php");
}
if ( !empty($_POST)) {
// keep track validation errors
$adminNameError = null;
$emailError = null;
$SKGError = null;
$ExtnError = null;
// keep track post values
$adminName = $_POST['adminName'];
$email = $_POST['email'];
$SKG = $_POST['SKG'];
$Extn = $_POST['Extn'];
// validate input
$valid = true;
if (empty($adminName)){
$adminNameError = "Please enter Administrator Name";
$valid = false;
}
if (empty($email)) {
$emailError = 'Please enter Email Address';
$valid = false;
} else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
$emailError = 'Please enter a valid Email Address';
$valid = false;
}
if (empty($SKG)) {
$SKGError = 'Please choose SKG';
$valid = false;
}
if(empty($Extn)){
$ExtnError = "Please enter Extension Number";
$valid = false;
}
// update data
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE admin set adminName ='$adminName', email ='$email', SKG ='$SKG', Extn ='$Extn' WHERE staffID = '$staffID'";
$q = $pdo->prepare($sql);
$q->execute(array($staffID,$adminName,$email,$SKG,$Extn));
Database::disconnect();
header("Location: ManageAdministrator.php");
}
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM admin where staffID = ?";
$q = $pdo->prepare($sql);
$q->execute(array($staffID));
$data = $q->fetch(PDO::FETCH_ASSOC);
$adminName = $data['adminName'];
$email = $data['email'];
$SKG = $data['SKG'];
$Extn = $data['Extn'];
$password = $data['password'];
Database::disconnect();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Update Administrator</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Capability Management">
<!-- CSS External Link -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/sb-admin.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<div id="wrapper">
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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" href="HomePage.php"><b> Training Log Database </b></a>
</div>
<ul class="nav navbar-right top-nav">
<li class="dropdown">
<!-- PHP REFER LOGIN NAME-->
<i class="fa fa-user"></i> M Farhan M Fazli <b class="caret"></b>
<ul class="dropdown-menu">
<li>
<i class="fa fa-fw fa-user"></i> Profile
</li>
<li class="divider"></li>
<li>
<!-- PHP LOGOUT FUNCTION -->
<i class="fa fa-fw fa-power-off"></i> Log Out
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items start here -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li>
<i class="fa fa-fw fa-dashboard"></i> Home
</li>
<li>
<i class="fa fa-fw fa-bar-chart-o"></i> Manage Administrator
</li>
<li>
<!-- Add new pages here -->
<i class="fa fa-fw fa-bar-chart-o"></i> Manage Staff
</li>
<li>
<i class="fa fa-fw fa-edit"></i> Manage Training<i class="fa fa-fw fa-caret-down"></i>
<ul id="demo" class="collapse">
<li>
Training Information
</li>
<li>
TBA
</li>
</ul>
</li>
<li>
<i class="glyphicon glyphicon-wrench"></i> Tools for Administrator<i class="fa fa-fw fa-caret-down"></i>
<ul id="demo1" class="collapse">
<li> Add News </li>
<li> Add Announcement </li>
<li> Search News </li>
<li> Search Announcement </li>
<li> View My Post </li>
</ul>
</li>
<li>
<i class="glyphicon glyphicon-info-sign"></i> About
</li>
<li>
<i class="glyphicon glyphicon-question-sign"></i> FAQs
</li>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<div class="row col-lg-12">
<h2 class="page-header"> Update Administrator Account </h2>
<div class="row col-lg-12">
<h3> Administrator details </h3>
<div class="row col-lg-12">
<form class="form-horizontal form-group" action="adminUpdate.php?id=<?php echo $staffID?>" method="post">
<!-- <div class="form-group col-lg-12 <?php echo !empty($staffIDError)?'error':'';?>">
<label>Administrator Staff ID</label>
<input class="form-control" name="staffID" type="text" value="<?php echo !empty($staffID)?$staffID:'';?>">
<?php if (!empty($staffIDError)): ?>
<span class="help-inline"><?php echo $staffIDError;?></span>
<?php endif; ?>
</div>-->
<div class="form-group col-lg-12 <?php echo !empty($adminNameError)?'error':'';?>">
<label>Administrator Name</label>
<input class="form-control" name="adminName" type="text" value="<?php echo !empty($adminName)?$adminName:'';?>">
<?php if (!empty($adminNameError)): ?>
<span class="help-inline"><?php echo $adminNameError;?></span>
<?php endif; ?>
</div>
<div class="form-group col-lg-12 <?php echo !empty($emailError)?'error':'';?>">
<label>Administrator Email</label>
<input class="form-control" name="email" type="text" value="<?php echo !empty($email)?$email:'';?>">
<?php if (!empty($emailError)): ?>
<span class="help-inline"><?php echo $emailError;?></span>
<?php endif; ?>
</div>
<div class="form-group col-lg-12 <?php echo !empty($ExtnError)?'error':'';?>">
<label> Extension Number </label>
<input class="form-control" name="Extn" type="text" value="<?php echo !empty($Extn)?$Extn:'';?>">
<?php if (!empty($ExtnError)): ?>
<span class="help-inline"><?php echo $ExtnError;?></span>
<?php endif; ?>
</label>
</div>
<div class="form-group col-lg-12 <?php echo !empty($SKGError)?'error':'';?>">
<label>SKG</label>
<select class="form-control" name="SKG" value="<?php echo !empty($SKG)?$SKG:'';?>">
<option> SKG 09 </option>
<option> SKG 18 </option>
<option> SKG 20 </option>
<option> SKG 16 </option>
<option> SKG 11 </option>
<option> SKG 13 </option>
<option> SKG 14 </option>
<option> SKG 12 </option>
<option> SKG 15 </option>
<option> SKG 10 </option>
<option> SKG 25 </option>
</select>
<?php if (!empty($SKGError)): ?>
<span class="help-inline"><?php echo $SKGError;?></span>
<?php endif; ?>
</div>
<!-- <div class="form-group col-lg-12 <?php echo !empty($passwordError)?'error':'';?>">
<label>Password</label>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" value="<?php echo !empty($password)?$password:'';?>">
<?php if (!empty($passwordError)): ?>
<span class="help-inline"><?php echo $passwordError;?></span>
<?php endif; ?> -->
</div>
<div class="form-actions col-lg-12">
<button type="submit" class="btn btn-success">Update</button>
<a class="btn btn-default" href="ManageAdministrator.php">Back</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div><!--wrap-->
</body>
</html>
Here's the Connect.php
<?php
class Database
{
private static $dbName = 'tlad' ;
private static $dbHost = 'localhost' ;
private static $dbUsername = 'root';
private static $dbUserPassword = '';
private static $cont = null;
public function __construct() {
exit('Init function is not allowed');
}
public static function connect()
{
// One connection through whole application
if ( null == self::$cont )
{
try
{
self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
}
catch(PDOException $e)
{
die($e->getMessage());
}
}
return self::$cont;
}
public static function disconnect()
{
self::$cont = null;
}
}
?>
Here's my table:
As I mentioned earlier, the read, create and delete function are working except for this update function aren't.
Please note: I've followed a tutorial on creating a CRUD datatable, while his template worked but my code aren't. Here's the tutorial's code for update template:
<?php
require 'database.php';
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: index.php");
}
if ( !empty($_POST)) {
// keep track validation errors
$nameError = null;
$emailError = null;
$mobileError = null;
// keep track post values
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
// validate input
$valid = true;
if (empty($name)) {
$nameError = 'Please enter Name';
$valid = false;
}
if (empty($email)) {
$emailError = 'Please enter Email Address';
$valid = false;
} else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
$emailError = 'Please enter a valid Email Address';
$valid = false;
}
if (empty($mobile)) {
$mobileError = 'Please enter Mobile Number';
$valid = false;
}
// update data
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE customers set name = ?, email = ?, mobile =? WHERE id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($name,$email,$mobile,$id));
Database::disconnect();
header("Location: index.php");
}
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM customers where id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
$name = $data['name'];
$email = $data['email'];
$mobile = $data['mobile'];
Database::disconnect();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="span10 offset1">
<div class="row">
<h3>Update a Customer</h3>
</div>
<form class="form-horizontal" action="update.php?id=<?php echo $id?>" method="post">
<div class="control-group <?php echo !empty($nameError)?'error':'';?>">
<label class="control-label">Name</label>
<div class="controls">
<input name="name" type="text" value="<?php echo !empty($name)?$name:'';?>">
<?php if (!empty($nameError)): ?>
<span class="help-inline"><?php echo $nameError;?></span>
<?php endif; ?>
</div>
</div>
<div class="control-group <?php echo !empty($emailError)?'error':'';?>">
<label class="control-label">Email Address</label>
<div class="controls">
<input name="email" type="text" value="<?php echo !empty($email)?$email:'';?>">
<?php if (!empty($emailError)): ?>
<span class="help-inline"><?php echo $emailError;?></span>
<?php endif;?>
</div>
</div>
<div class="control-group <?php echo !empty($mobileError)?'error':'';?>">
<label class="control-label">Mobile Number</label>
<div class="controls">
<input name="mobile" type="text" value="<?php echo !empty($mobile)?$mobile:'';?>">
<?php if (!empty($mobileError)): ?>
<span class="help-inline"><?php echo $mobileError;?></span>
<?php endif;?>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Update</button>
<a class="btn" href="index.php">Back</a>
</div>
</form>
</div>
</div> <!-- /container -->
</body>
</html>
Your execute has 5 parameters, but query wants 6.
$sql = "UPDATE admin set staffID = ?, adminName = ?, email = ?, SKG = ?, Extn = ? WHERE staffID = ?";
$q = $pdo->prepare($sql);
$q->execute(array($staffID, $adminName, $email, $SKG, $Extn, $staffID));
Also were missing $ in front of email, SKG and Extn.
Related
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.
I have a login form(index.php) which allows students to access their portal, the students' registration number and password is then checked if inserted(login.php) and proceeds to a class(StudentLogin.php) which will then allow the students access their portal if at all the credentials match with the ones in the database. On entering the correct credentials, the process doesn't proceed to the stud_page.php.....I would appreciate any help on this cause i don't understand what is happening.
Below is the index.php:
<?php
//Start session
if(!isset($_SESSION)) { session_start(); }
unset($_SESSION['ID']);
unset($_SESSION['REG_NUM']);
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Portal System</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/style.css">
<!-- <link rel="stylesheet" href="static/css/style.css"/> -->
</head>
<body>
<!-- Header -->
<nav class="navbar navbar-fixed-top" style="background-color: green;" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">portal</a>
</div>
</div><!-- /.container-fluid -->
</nav>
<!-- End Header -->
<div class="background">
<div class="container">
<div class="jumbotron bg-success text-warning">
<h1 class="text-center">portal</h1>
<h3 class="text-center"> Welcome to The Portal.</h3>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-offset-4">
<div class="login-con">
<h3>Student Log-in</h3><hr>
<?php
if(isset($_SESSION['ERROR_MSG_ARRAY']) && is_array($_SESSION['ERROR_MSG_ARRAY']) && COUNT($_SESSION['ERROR_MSG_ARRAY']) > 0) {
foreach($_SESSION['ERROR_MSG_ARRAY'] as $msg) {
echo "<div class='alert alert-danger'>";
echo $msg;
echo "</div>";
}
unset($_SESSION['ERROR_MSG_ARRAY']);
}
?>
<form action="process/login.php" method="POST" role="form">
<div class="form-group has-warning has-feedback">
<label for="reg_num">Registration Number</label>
<input type="text" name="reg_num" id="reg_num" class="form-control" autocomplete="off" placeholder="Registration Number">
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-warning has-feedback">
<label>Password</label>
<input id="password" type="password" autocomplete="off" class="form-control" placeholder="Password" name="password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<button type="submit" onclick="showSomeMessage()" name="submit" class="btn btn-info">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
login.php below:
<?php
require("../admin/database.php");
require("../class/StudentLogin.php");
if(isset($_POST['submit'])){
$regnum = trim($_POST['regnumber']);
$password = trim($_POST['password']);
$loginStud = new StudentLogin($reg_num, $password);
$rtnlogin = $loginStud->Studlogin();
}
$conn->close();
?>
Then the StudentLogin class is:
<?php
class StudentLogin
{
private $_regnumber;
private $_password;
public function __construct($c_reg_num, $c_password){
$this->_regnumber = $c_reg_num;
$this->_password = $c_password;
}
public function StudLogin(){
global $conn;
// starting session
session_start();
// valiidate errors
$error_msg_array = array();
// error msg
$error_msg = FALSE;
if($this->_reg_num == ""){
$error_msg_array[] = "Please input your Registration Number";
$error_msg = TRUE;
}
if($this->_password == ""){
$error_msg_array[] = "Please input your password";
$error_msg = TRUE;
}
if($error_msg){
$_SESSION['ERROR_MSG_ARR'] = $error_msg_array;
header("location: http://localhost/project/index.php");
exit();
}
$sql = "SELECT * FROM students WHERE regnumber ='$reg_num' AND password ='$password' LIMIT 1";
if(!$stmt = $conn->prepare($sql)){
echo $stmt->error;
} else {
$stmt->bind_param("ss", $this->_reg_num, $this->_password);
$stmt->execute();
$result = $stmt->get_result();
}
if($result->num_rows > 0) {
// login successful
$row = $result->fetch_assoc();
// session creation
session_regenerate_id();
$_SESSION['reg_num'] = $row["regnunmber"];
$_SESSION['name'] = $row["name"];
session_write_close();
header("location: http://localhost/project/stud_page.php");
} else {
// Login failed
$error_msg_array[] = "The Registration Number and Password you entered is incorrect.";
$error_msg = TRUE;
if($error_msg) {
$_SESSION['ERROR_MSG_ARR'] = $error_msg_array;
header("location: http://localhost/project/index.php");
exit();
}
$stmt->free_result();
}
$result->free();
return $result;
}
}
?>
MySQL database, table students contains the following columns:
$sql="INSERT INTO `students`(`name`, `education`, `regnumber`, `nationality`, `gender`, `phone`, `photo`, `branch`,`password`)
VALUES ('$name','$education','$reg_num','$nationality','$gender','$phone','$target_file','$branch','$ency_pass')";
You have validation on login.php, which is not loaded before form is send.
And if you can i would recommend you using dibi, because this work with database is not properly right and can cause some problems if u are going to use that in production
https://dibiphp.com/en/
so on my site, the admin can assign a job to a user and that job will automatically have the status: waiting to be accepted. I have now created a drop down box on the job page so that the user can either decline or accept the job with that drop down box. however im unsure of the coding needed to update the database field based on what the user selects.
what im aiming for is: the user selects a status, then clicks the change button to update the status of the job.
current code:
<?php
if(!isset($_SESSION))
{
session_start();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<title>Tyre Hire</title>
<link rel="stylesheet" type="text/css" href="css/mystyle.css"/>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<header>
<img class="img-responsive" src ="images/Logo.png" alt ="logo"/>
</header>
</div>
</div>
<?php
require_once ("config.inc.php");
try
{
$conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
}
catch(PDOException $exception)
{
echo "Oh no, there was a problem" . $exception->getMessage();
}
if(!isset($_SESSION["username"]))
{
//user tried to access the page without logging in
header( "Location: add.php" );
}
$login = $_SESSION['user_ID'];
$query = "SELECT * FROM login WHERE user_ID = :user_ID";
$term = $conn->prepare($query);
$term->bindValue(':user_ID', $login);
$term->execute();
$login = $term->fetch(PDO::FETCH_OBJ);
$status = "Waiting to be accepted";
$status2 = "Accept Job";
$status3 = "Decline Job";
if(isset($_SESSION["username"]))
{
echo "Welcome, you are now logged in as <b>".$_SESSION['username']."</b> <img class='clientView' src='images/loginIcon.png' alt='client'>"; }
else {
echo "You are currently not logged in";
};
?>
<div class="row">
<div class="col-xs-12">
<br>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="main.php">Tyre Hire</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li> Home <span class="glyphicon glyphicon-print"></span></li>
<li> Search <span class="glyphicon glyphicon-print"></span></li>
<li><?php echo "<a href='all-jobs.php?user_id=" . $login->user_ID . "&occupation=". $login->occupation ."''> Current Jobs <span class='glyphicon glyphicon-print'></span></a>";?> </li>
<li> Register Interest <span class="glyphicon glyphicon-print"></span></li>
<li> Logout <span class="glyphicon glyphicon-print"></span></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="right">
<h2>Current Jobs</h2>
<p>One of the best sites to find the best qualified and skilled drivers in the UK.</p>
<form class="form-horizontal formApply" action="" method="POST">
<h2><u>Job Details </u></h2>
<div class="form-group">
<?php
echo "<h3>Job role :".$worker->jobTitle."</h3>";
echo "<ul>";
echo "<h3> About the role </h3>";
echo "<li><b>Company Name:</b>".$worker->company."</li>";
echo "<li><b>Job Description:</b>".$worker->jobDescription."</li>";
echo "<h3>shift pattern</h3>";
echo "<li><b>Start Time: </b>".$worker-> startTime."</li>";
echo "<li><b>End Time: </b>".$worker-> endTime."</li>";
echo "<br />";
echo "<li><b>start Date:</b>".$worker->startDate."</li>";
echo "<li><b>Job Expiry Date:</b>".$worker->expiry."</li>";
echo "<b><h4>Current Status: </b>".$worker->status."</h4>";
echo "</ul>";
?>
<div class="form-group">
<label class="control-label col-sm-2" for="search"> Status</label>
<div class="col-sm-3">
<select class="form-control" name="status" >
<option value="<? echo $status;?>"><?php echo $status;?></option>
<option value="<? echo $status2;?>"><?php echo $status2;?></option>
<option value="<? echo $status3;?>"><?php echo $status3;?></option>
</select>
<input type="hidden" value="<?php echo $status; ?>" name="status">
</div>
<div class="form-group">
<!--<label class="control-label col-sm-2" for="search"></label> -->
<div class="col-sm-3">
<!-- <select class="form-control" name="status" >
<option value="<? echo $job;?>"><?php echo $job;?></option>
</select> -->
<input type="hidden" value="<?php echo $job; ?>" name="job_id">
</div>
</div>
</div>
<input class = "buttonA" type="submit" name="Apply" value="Change status"/>
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div id="BottomArea">
<h4> Recruitment Agencies </h4>
<div class="row">
<div class="col-xs-3">
<img class="FxPic img-responsive" src="images/fxpic.png" alt="fx-logo">
</div>
<div class="col-xs-3">
<img class="driverhire img-responsive" src="images/driverhire.jpg" alt="driverhire">
</div>
<div class="col-xs-3">
<img class="logi img-responsive" src="images/logi.png" alt="logi-logo">
</div>
<div class="col-xs-3">
<img class="pebble img-responsive" src="images/noel.png" alt="pebbles">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<footer>
<img id="logoFoot" src ="images/Logo.png" alt ="logo"/>
<p><b>Address: 5A twickenham road, london SJ5 7AE</b></p>
</footer>
</div>
</div>
<script src=myjs.js></script>
</div>
</body>
</html>
attempted it after reading the update manual, no errors but upon clicking the button it gives a blank page.:
<?php
include ("db_fncs.php");
try{
$conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
}
catch (PDOException $exception)
{
echo "Oh no, there was a problem" . $exception->getMessage();
}
$status = $_POST["status"];
$job = $_POST['job_id'];
print_r($_POST);
$query = "UPDATE jobs SET status = :status WHERE job_id = :job_id AND status = :status";
// Prepare statement
$stmt = $conn->prepare($query);
$stmt->bindValue(':status', $status);
$stmt->bindValue(':job_id', $job);
// execute the query
$stmt->execute();
//$stmt->commit();
echo $stmt->rowCount() . " records UPDATED successfully";
?>
The basic syntax for UPDATE is:
UPDATE <my_table>
SET <update_column_name> = <some_value>
WHERE <identifying_column_name> = <some_value>
In your case, it would probably look something like:
UPDATE jobs
SET status = <new_job_status>
WHERE userid = <user_id>
AND jobid = <job_id>
I am trying to get my login php working. I can't find what's wrong. I've had it working before, but it stopped all of the sudden. I am using bootstrap also, but I don't think that would cause any problems. Everything between the php and the form seems to match up. I am using a javascript and css modal for the login form, but I don't think that would effect it either.
PHP:
<?php
session_start();
include_once 'dbconnect.php';
if(isset($_SESSION['usr_id'])) {
echo "Successfully Logged In!";
//header("Location: index.php");
}
if (isset($_POST['login'])) {
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$result = mysqli_query($con, "SELECT * FROM users WHERE email = '" . $email . "' and password = '" . md5($password) . "'");
?>
<!--<script>
alert("<?php echo 'Result is: '.$result; ?>");
</script> -->
<?php
$row = mysqli_fetch_array($result);
echo $row;
if ($row != NULL) {
$_SESSION['usr_id'] = $row['id'];
$_SESSION['usr_name'] = $row['name'];
// header("Location: index.php");
} else {
$errormsg = "Incorrect Email or Password!!!";
}
}
?>
Here is my login modal with the form:
<!-- The Modal -->
<div id="login" class="modal">
<!-- Modal content -->
<div class='js-fade fade-in is-paused'>
<div class="modal-content">
<span class="close" data-dismiss="modal">x</span>
<form role="form" action="index.php" method="post" name="loginform">
<fieldset>
<legend>Login</legend>
<div class="form-group">
<label for="name">Email</label>
<input type="text" name="email" id="email" placeholder="Your Email" required class="form-control" />
</div>
<div class="form-group">
<label for="name">Password</label>
<input type="password" name="password" id="password" placeholder="Your Password" required class="form-control" />
</div>
<div class="form-group">
<input type="submit" name="login" value="login" class="btn btn-info login" role="button" />
</div>
</fieldset>
<div class="signupbtn">
<li>Don't have an account? Sign Up here.</li>
</div>
</form>
</div>
</div>
</div>
Navbar:
<!-- Nav Bar -->
<nav class="navbar navbar-default navbar-fixed-top navbar-left">
<div class="container">
<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>
<a class="navbar-brand brand" href="#" style="font-family: Warnes">Unleasht</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="navbarli">HOME</li>
<li class="navbarli">ABOUT</li>
<li class="navbarli">MUSIC</li>
<li class="navbarli">CONTACT</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php
function loggedIn(){
if(isset($_SESSION['usr_id']))
{ echo '<li class="dropdown">
'. $_SESSION['user'] .'<span class="caret"></span>
<ul class="dropdown-menu">
<li>'. $_SESSION['usr_name'] .'</li>
<li>Account</li>
<li role="separator" class="divider"></li>
<li><a action="login/logout.php">Logout</a></li>
</ul>
</li>';
}else{
unset($_SESSION['usr_id']);
echo '<li><span class="glyphicon glyphicon-log-in navbarli"></span> Login</li>';
}
}
loggedIn();
?>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
What am I doing wrong?
You can not set $_SESSION['usr_id'] after you have sent any header, try following code:
<?php
session_start();
include_once 'dbconnect.php';
if(isset($_SESSION['usr_id'])) {
echo "Successfully Logged In!";
}elseif (isset($_POST['login'])) {
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$result = mysqli_query($con, "SELECT * FROM users WHERE email = '" . $email . "' and password = '" . md5($password) . "'");
if (mysqli_num_rows($result)==1) {
$row = mysqli_fetch_array($result);
$_SESSION['usr_id'] = $row['id'];
$_SESSION['usr_name'] = $row['name'];
echo "OK fine";
} else {
echo "Incorrect Email or Password!!!";
}
}
?>
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
}
//}
}
}
}
?>