I'm trying to retrieve my logged in user data to no avail. Please check my
enter code here private function getUserData($user_name)
{
// if database connection opened
if ($this->databaseConnection()) {
// database query, getting all the info of the selected user
$query_user = $this->db_connection->prepare("SELECT * FROM users WHERE user_name='$_SESSION['user_name']'");
$query_user->bindValue(':user_name', $user_name, PDO::PARAM_STR);
$query_user->execute();
// get result row (as an object)
return $query_user->fetchObject();
} else {
return false;
}
}
Got the way to move about it ,Thanks #ADyson for the response and follow up
code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>YOUR ORDER , We will contact you in a few !!!!</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/main.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php include 'header.php'; ?>
<section>
<div class="container">
<strong class="title">MY ORDERS</strong>
</div>
<div class="profile-box box-left">
<?php
require('db.php');
// SQL query
$strSQL = "SELECT user_name, phone, firstname, lastname, service, referal,user_registration_datetime FROM users WHERE user_name = '".$_SESSION['user_name']."'";
// Execute the query (the recordset $rs contains the result)
$rs = mysqli_query($myConnection, $strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysqli_fetch_array
while($row = mysqli_fetch_array($rs)) {
echo WORDING_PROFILE_PICTURE . '<br/>' . $login->user_gravatar_image_tag;
echo "<div class='info'> <strong>NAME:</strong> <span>".$row['firstname'].", ".$row['lastname']."</span></div>";
echo "<div class='info'><strong>phone No:</strong> <span>".$row['phone']."</span></div>";
echo "<div class='info'><strong>SERVICE:</strong> <span>".$row['service']."</span></div>";
echo "<div class='info'><strong>REFERAL:</strong> <span>".$row['referal']."</span></div>";
echo "<div class='info'><strong>DATE QUERIED:</strong> <span>".$row['user_registration_datetime']."</span></div>";
}
// Close the database connection
mysqli_close($myConnection);
?>
<div class="options">
<a class="btn btn-primary" href="editprofile.php">Edit Profile</a>
<a class="btn btn-success" href="changepassword.php">Change Password</a>
</div>
</div>
</section>
<script src="assets/js/jquery-3.1.1.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>
This fairly simple issue is vexing me. I have an html page laid out with CSS. I have a simple php page that returns the latest record from a mysql site. I need to display this information in the html page in the "leftContent" div.
working 'latest.php' page is:
<?php
/*
Return the latest date and record for the left pane.
*/
include 'ESP8266_dbLogin.php';
$result = mysqli_query($link, "SELECT * FROM `thLog` ORDER BY logID DESC LIMIT 1") or die ("Connection error");
while($row = mysqli_fetch_array($result)) {
echo "Date: " . $row['logDate'] . "<br>";
echo "lightVal: " . $row['lightVal'];
}
mysqli_close($link);
?>
'index.html' code is as follows, with the target DIV of contentLeft for the php variables:
<!DOCTYPE html>
<!-- Basic Layout -->
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Sparks - Monitor</title>
<link rel="stylesheet" type="text/css" href="css/default.css">
<link href='//fonts.googleapis.com/css?family=Baloo' rel='stylesheet'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript" src="data24.js" ></script>
</head>
<body>
<div id="wrapper">
<div id="main">
<div id="banner">
<div id="bannerLeft">
<img class="bannerImg" alt="ESP8266 Logo" src="images\imgESP8266.png">
</div>
<div id="bannerRight">
<img class="bannerImg" alt="Settings Icon" src="images\imgGear.png">
</div>
<div id="bannerMain">
<h1>SPARKS Energy Monitor - Home</h1>
</div>
</div>
<div class="content" id="contentLeft">
<h2>Current Usage:</h2>
<p> The current lightVal and date should be here<p>
</div>
<div class="content" id="contentRight">
Generating chart, please wait...
</div>
</div>
</div>
</body>
<html>
Any help is gratefully received on the most efficient way to get the php variables (lightVal) into the html page. I know, stupid question!!
1) Rename your index.html to index.php
2) Replace your target div with your PHP code:
<div class="content" id="contentLeft">
<h2>Current Usage:</h2>
<?php
/*
Return the latest date and record for the left pane.
*/
include 'ESP8266_dbLogin.php';
$result = mysqli_query($link, "SELECT * FROM `thLog` ORDER BY logID DESC LIMIT 1") or die ("Connection error");
while($row = mysqli_fetch_array($result)) {
?>
<p class="dateClass"><?=$row['logDate']?></p>
<p class="lightValClass"><?=$row['lightVal']?></p>
<?
}
mysqli_close($link);
?>
</div>
It should be enough, just call index.php from browser.
I am creating a PHP/MySQL based application and it need to be able to carry over session variables into the DataTable plugin I use on a page in my app. The application is rather complicated, so I will explain how it works before I ask specific questions.
On index.php, there is a dropdown menu that shows the departments that use this application within my organization. The department list is generated by a mySQL table that has their department name and department code. The $dept variable stores the department code value from the selected option in the dropdown menu on submit. In turn, the $_SESSION["department"] variable stores $dept and redirects to the checkin page if successful.
<?php
require_once('connection.php');
session_start();
if (isset($_POST['submit']))
{
$dept = $_POST['dept'];
$_SESSION["department"] = $dept;
header("Location: checkin.php");
}
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Visitor Management</title>
<link rel="stylesheet" href="css/foundation.min.css" />
<link rel="stylesheet" href="css/app.css" />
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/24365087-b739-4314-af6e-741946b60bef.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/b05259d9-ca62-44a8-8a19-d3facdbd64df.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/2603d516-f938-4b52-ae3a-11d25bb4c555.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/510266cf-74ab-4fa8-9b39-dd37b90d6ab0.css"/>
</head>
<body>
<!-- nav -->
<div class="top-bar">
<div class="top-bar-left">
<ul class="menu">
</ul>
</div>
<div class="top-bar-right">
</div>
</div>
<div class="row text-center" style="margin-top: 5%;">
<h1>Syracuse University</h1>
<h2>Visitor Management</h2>
<br/>
<form id="dept" method="post" name="dept">
<?php
echo "<select name='dept'>";
echo '<option>'.'Please select a department'.'</option>';
$query = mysqli_query($VisitorManagement, "SELECT * FROM departments");
while($row=mysqli_fetch_array($query))
{
echo "<option value='". $row['code']."'>".$row['name']
.'</option>';
}
echo '</select>';
?>
<input type="submit" class="button" value="Submit" name="submit">
</form>
</div>
<script src="js/vendor/jquery.min.js"></script>
<script src="js/vendor/what-input.min.js"></script>
<script src="js/foundation.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
The session variable is then carried throughout the site and is used to determine which table needs to be shown. For instance, in checkin.php, we need to display staff members in a dropdown list. We have multiple tables based on the departments using the application. One table we have is called ts_staff If the session variable is stored as the string ts, we do the following steps to make sure the app is connecting to the right database:
We store the session variable from index.php into a global variable on checkin.php $dept = $_SESSION[department];
We create another new variable to concatenate the global variable and the _staff string which is used in all our mySQL staff tables: $staffTable = $dept . "_staff";
Lastly, we use the $staffTable variable as the database table that needs to be displayed: $query = mysqli_query($VisitorManagement, "SELECT * FROM {$staffTable}");
Here's the full checkin.php code:
<?php
// connect to database
require_once('connection.php');
session_start();
//get session variable, if empty, unset and logout
if(empty($_SESSION['department'])) {
session_unset();
session_destroy();
header("Location: index.php");
} else {
$dept = $_SESSION[department];
}
//submit values on submit
if (isset($_POST['submit']))
{
// store form data values
$suid = mysqli_real_escape_string($VisitorManagement, $_POST['suid']);
$staff = mysqli_real_escape_string($VisitorManagement, $_POST['staff']);
$checkinTable = $dept . "_checkin";
// insert varaibles into table rows
$sql = "INSERT INTO {$checkinTable} (suid, staffMember) VALUES ('$suid', '$staff')";
// check if row was inserted correctly
if (mysqli_query($VisitorManagement, $sql)) {
header('Location: thank-you.php');
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($VisitorManagement);
}
}
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Visitor Management</title>
<link rel="stylesheet" href="css/foundation.min.css" />
<link rel="stylesheet" href="css/app.css" />
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/24365087-b739-4314-af6e-741946b60bef.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/b05259d9-ca62-44a8-8a19-d3facdbd64df.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/2603d516-f938-4b52-ae3a-11d25bb4c555.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/510266cf-74ab-4fa8-9b39-dd37b90d6ab0.css"/>
</head>
<body>
<!-- nav -->
<div class="top-bar">
<div class="top-bar-left">
<ul class="menu">
<li>Check-In</li>
</ul>
</div>
<div class="top-bar-right">
<ul class="menu">
<li>Admin Login</li>
<li>Logout</li>
</ul>
</div>
</div>
<div class="row text-center" style="margin-top: 5%;">
<h1>Syracuse University</h1>
<!-- replace with whatever department they select -->
<h2>Technical Services</h2>
</div>
<div class="row">
<form id="checkin" method="post" name="checkin">
<div class="row">
<div class="medium-12 columns">
<label>Please Swipe Your SUID Card
<input type="text" placeholder="SUID Number Here" id="suid" name="suid" required>
</label>
</div>
<div class="medium-12 columns">
<label>Who Are You Here to See?
<?php
$staffTable = $dept . "_staff";
echo "<select name='staff'>";
echo '<option value="">'.'Please select a staff member'.'</option>';
$query = mysqli_query($VisitorManagement, "SELECT * FROM {$staffTable}");
while($row=mysqli_fetch_array($query))
{
echo "<option value='". $row['fullName']."'>".$row['fullName']
.'</option>';
}
echo '</select>';
// close connection
mysqli_close($VisitorManagement);
?>
</label>
</div>
<div class="medium-12 columns">
<input type="submit" class="button" value="Submit" name="submit">
</div>
</div>
</form>
</div>
<script src="js/vendor/jquery.min.js"></script>
<script src="js/vendor/what-input.min.js"></script>
<script src="js/foundation.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
The problem is that on reports.php, I am using the DataTables plugin to dynamically organize and filter a table, but I need to be able to carry the session variable over into the plugin so it knows to organize the specific table based on what the user selected on the index.php screen.
reports.php just calls DataTables and using another page, response.php to turn the data from the table into JSON to be displayed. Here's reports.php:
<?php session_start();
if(empty($_SESSION['department'])) {
session_unset();
session_destroy();
header("Location: index.php");
} else {
$dept = $_SESSION[department];
}
$checkinTable = $dept . "_checkin";
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Visitor Management</title>
<link rel="stylesheet" href="../css/foundation.min.css" />
<link rel="stylesheet" href="../css/app.css" />
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/24365087-b739-4314-af6e-741946b60bef.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/b05259d9-ca62-44a8-8a19-d3facdbd64df.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/2603d516-f938-4b52-ae3a-11d25bb4c555.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/510266cf-74ab-4fa8-9b39-dd37b90d6ab0.css"/>
<link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.css"/>
</head>
<body>
<?php
if (!isset($_SESSION['user'])) {
header("Location: ../login.php"); // If session is not set that redirect to Login Page
}
?>
<div class="top-bar admin">
<div class="top-bar-left">
<ul class="menu">
<li class="menu-text">Visitor Management</li>
</ul>
</div>
<div class="top-bar-right">
<ul class="menu">
<li>Logout</li>
<li>Help</li>
</ul>
</div>
</div>
<div class="medium-2 columns dash">
<ul>
<li>Dashboard</li>
<li>Staff</li>
<li class="active">Reports</li>
</ul>
</div>
<div class="medium-10 columns">
<div class="row checkin">
<h2>Reports</h2>
<table class="checkin" id="checkin">
<thead>
<tr>
<th>ID</th>
<th>SUID #</th>
<th>Staff Member</th>
<th>Student Name</th>
<th>Student Email</th>
<th>Check In Date/Time</th>
</tr>
</thead>
</table>
<!--<div class="float-left">
Export to Excel
</div>
<div class="float-right">
</div>-->
</div>
</div>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script src="../js/vendor/what-input.min.js"></script>
<script src="../js/foundation.min.js"></script>
<script src="../js/app.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.js"></script>
<script>
$(document).ready(function() {
$('#checkin').DataTable({
"bProcessing": true,
"serverSide": false,
"dom": 'lBfrtip',
"buttons": [
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
],
"ajax":{
url :"response.php", // json datasource
type: "post", // type of method ,GET/POST/DELETE
data: {}
}
});
});
</script>
</body>
</html>
Here's response.php:
<?php
//include connection file
include_once("../connection.php");
// initilize all variable
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
//define index of column
$columns = array(
0 => 'id',
1 => 'suid',
2 => 'staffMember',
3 => 'studentName',
4 => 'studentEmail',
5 => 'checkinDateTime'
);
$where = $sqlTot = $sqlRec = "";
// check search value exist
if( !empty($params['search']['value']) ) {
$where .=" WHERE ";
$where .=" ( studentName LIKE '".$params['search']['value']."%' ";
$where .=" OR staffMember LIKE '".$params['search']['value']."%' ";
$where .=" OR studentEmail LIKE '".$params['search']['value']."%' ";
$where .=" OR suid LIKE '".$params['search']['value']."%' ";
$where .=" OR checkinDate LIKE '".$params['search']['value']."%' )";
}
// getting total number records without any search
$sql = "SELECT id, suid, staffMember, studentName, studentEmail, date_format(checkinDateTime, '%b %d, %Y, %h:%i %p') as checkinDateTime FROM `ts_checkin`";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {
$sqlTot .= $where;
$sqlRec .= $where;
}
//$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
$queryTot = mysqli_query($VisitorManagement, $sqlTot) or die("database error:". mysqli_error($VisitorManagement));
$totalRecords = mysqli_num_rows($queryTot);
$queryRecords = mysqli_query($VisitorManagement, $sqlRec) or die("error to fetch check-in data");
//iterate on results row and create new index array of data
while( $row = mysqli_fetch_row($queryRecords) ) {
$data[] = $row;
}
$json_data = array(
"draw" => intval( $params['draw'] ),
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
?>
In response.php, I need to able to replace ts_checkin, which is shown on this line:
$sql = "SELECT id, suid, staffMember, studentName, studentEmail, date_format(checkinDateTime, '%b %d, %Y, %h:%i %p') as checkinDateTime FROM `ts_checkin`";`
with a variable called $checkinTable that would concatenate similar to how checkin.php does with the staff table. So essentially I would like to have $checkinTable = $dept . "_checkin" with $dept equaling the value of the session variable.
When I go to do this, I get this error from DataTables: DataTables warning: table id=checkin - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
Is it possible to get this working? I would like to keep DataTables as its the best way to achieve on-the-fly table filtering, searching, and sorting (plus it's a highly requested feature by our departments). But I need to be able to set the table based on the session variable.
I apologize for the length of this question. If there needs to be clarification, let me know.
I'm not certain to understand the question...
Are you saying this is not working ?
Did you try it written like this?
(notice the space after FROM. It is necessary!)
$checkinTable = $dept . "_checkin";
$sql = "SELECT id, suid, staffMember, studentName, studentEmail, date_format(checkinDateTime, '%b %d, %Y, %h:%i %p') as checkinDateTime FROM " . $checkinTable;
For sure, $dept has also to be defined.
And the resulting $checkinTable has to be an existing table name.
Ok...
This looks to be missing in your response.php:
session_start();
$dept = $_SESSION[department];
$checkinTable = $dept . "_checkin";
I have two PHP pages:
giardino.php:
<?php
SESSION_START();
if (isset($_SESSION['utente'])){
?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="immagini/favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" href="css/stile.css"/>
</head>
<body>
<div data-role="page" data-theme="d">
<div data-role="header">
Ambienti
<a href="logout.php" data-role="button" data-theme="b" data-icon="delete" >Logout</a>
<h1>Domos - Giardino</h1>
</div><!-- /header -->
<div data-role="content" id="centramento">
<?php
include("configurazione.php");
$id_stanza=1;
$pin=26;
//lettura stato attuale
$comando="select luci from casa where ID_stanza=1";
$query=mysql_query($comando,$connessione);
while($riga=mysql_fetch_array($query)){
$oldstate=$riga['luci'];
}
if($oldstate == 0){
$newstate='accendi luce';
$theme='e';
}
else{
$newstate='spegni luce';
$theme='a';
}
echo "<a href='luce.php' data-role='button' data-theme='$theme' id='radio'>$newstate</a>"
?>
</div><!-- /content -->
<div data-role="footer" data-position="fixed">
<h4>Credits: Silvio Mattiello 5C Informatica 2014/2015</h4>
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>
<?php
}
else{
header("location:home.php?msg=6");
}
?>
luce.php:
<?php
$id_stanza=1;
$pin=$_GET=26;
$comando = escapeshellcmd("sudo /var/www/domotica/python/luce.py $pin $id_stanza");
$esito = exec($comando);
if ($esito == "allarme attivato"){
header("location:ambienti.php");
exit();
}
else {
header("location:giardino.php");
exit();
}
?>
When I click the button on the first page, I get redirected to the second page.
In the second page, there are some operations and then I get redirected to the first page (or another page, ambienti.php).
But when I am redirected to the first page again, the button on this page (giardino.php) doesn't work. I can't click it. Why?
try to use a require instead of the include, to see if there is any error... It seems to be something with include.
Also, you could try to add 302 http to the header like this and add the full path
header('Location: http://server_name/ambienti.php', true, 302);
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 8 years ago.
There are quite a few solutions available for this error but none seems to be working for me. I am a new php developer and trying to create web site using php programs.
The error I'm getting is "Warning: Cannot modify header information - headers already sent by (output started at /home/influss/public_html/Influsstest/hiremain.php:39) in /home/influss/public_html/Influsstest/hiremain.php on line 74"
I have checked the line no. 39 and do not find any whitespace before or after the php. also there are no white spaces in the beginning or the end of the program but still I'm getting this error.
the code is as follows:
`
<!doctype html>
<html><!-- InstanceBegin template="/Templates/registrtion.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Hire Main</title>
<!-- InstanceEndEditable -->
<link href="/css/styles-reg.css" rel="stylesheet" type="text/css" media="all">
<link href="/css/reg.css" rel="stylesheet" type="text/css" media="all"/>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,500' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Slabo+13px' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700' rel='stylesheet' type='text/css'>
<!-- InstanceBeginEditable name="head" -->
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all">
<!-- InstanceEndEditable -->
</head>
<body>
<div id="wrapper">
<div id="top">
<div id = "logo">
<img src="images/logo2.jpg">
</div>
<div id = "social-media">
<p>For additional information<br>Call Phone No.</p>
<ul>
<li><img src="/images/icons/facebook1.png"></li>
<li><img src="/images/icons/twitter1.png"></li>
<li><img src="/images/icons/linkedin1.png"></li>
<li><img src="/images/icons/googleplus1.png"></li>
</ul>
</div>
</div>
<!-- <div id="Banner">
</div>
--> <div id="Content-wrapper">
<div id="content">
<!-- InstanceBeginEditable name="content" -->
**<?php**
error_reporting(E_ALL); ini_set('display_errors', 'On');
function renderForm($id, $error)
{
?>
<?php
if ($error != '')
{
echo '<div style="margin:0 200px;padding:4px; color:red ;font-weight:bold;">'.$error.'</div>';
}
?>
<form action="hiremain.php" method="post" class="newreg">
<fieldset class="row1">
<p>
<label class="labelstyle">Enter Registration ID: *</label>
<input type="text" name="regid" value="<?php echo $id;?>"/>
</p>
</fieldset>
<p></p>
<input class="button1" type="submit" name="submit" value="Get Details">
</form>
<p></p>
<?php
}
?>
<?php
include('connect.php');
if (isset($_POST['submit']))
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header('location:hireedit.php?regid='.$id);
}
else
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header("location:hireedit.php?regid=" . $id);
}
Else
{
$error = "Please register first";
renderForm($id, $error);
}
}
mysql_free_result($result);
}
else
{
$error = "";
$id="";
renderform($id, $error);
}
?>
Register a Request
Home
<p></p>
<!-- InstanceEndEditable -->
</div>
</div>
<div id="footer">
<p>©Copyright 2014 • All rights Reserved • Influss.com, Chennai, Mob: +9112345-12345, E-mail: abc#influss.com</p>
</div>
</div>
</body>
<!-- InstanceEnd -->
</html>
`
The error happens to be in the line which is marked by *.
Request somebody help me out on this.
You can't send headers after an html output.
You have to put them before
<!doctype html>
You can resolve this using:
<?php
error_reporting(E_ALL); ini_set('display_errors', 'On');
function renderForm($id, $error)
{
if ($error != '')
{
$problems = '<div style="margin:0 200px;padding:4px; color:red ;font-weight:bold;">'.$error.'</div>';
}
}
include('connect.php');
if (isset($_POST['submit']))
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header('location:hireedit.php?regid='.$id);
}
else
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header("location:hireedit.php?regid=" . $id);
}
Else
{
$error = "Please register first";
renderForm($id, $error);
}
}
mysql_free_result($result);
}
else
{
$error = "";
$id="";
renderform($id, $error);
}
?>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/registrtion.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Hire Main</title>
<!-- InstanceEndEditable -->
<link href="/css/styles-reg.css" rel="stylesheet" type="text/css" media="all">
<link href="/css/reg.css" rel="stylesheet" type="text/css" media="all"/>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,500' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Slabo+13px' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700' rel='stylesheet' type='text/css'>
<!-- InstanceBeginEditable name="head" -->
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all">
<!-- InstanceEndEditable -->
</head>
<body>
<div id="wrapper">
<div id="top">
<div id = "logo">
<img src="images/logo2.jpg">
</div>
<div id = "social-media">
<p>For additional information<br>Call Phone No.</p>
<ul>
<li><img src="/images/icons/facebook1.png"></li>
<li><img src="/images/icons/twitter1.png"></li>
<li><img src="/images/icons/linkedin1.png"></li>
<li><img src="/images/icons/googleplus1.png"></li>
</ul>
</div>
</div>
<!-- <div id="Banner">
</div>
--> <div id="Content-wrapper">
<div id="content">
<!-- InstanceBeginEditable name="content" -->
<?php
echo $problems;
?>
<form action="hiremain.php" method="post" class="newreg">
<fieldset class="row1">
<p>
<label class="labelstyle">Enter Registration ID: *</label>
<input type="text" name="regid" value="<?php echo $id;?>"/>
</p>
</fieldset>
<p></p>
<input class="button1" type="submit" name="submit" value="Get Details">
</form>
<p></p>
Register a Request
Home
<p></p>
<!-- InstanceEndEditable -->
</div>
</div>
<div id="footer">
<p>©Copyright 2014 • All rights Reserved • Influss.com, Chennai, Mob: +9112345-12345, E-mail: abc#influss.com</p>
</div>
</div>
</body>
<!-- InstanceEnd -->
</html>