Fetch data from database in php - php

Hi In my application I designed one form with HallTicketNo if i click the submit button it will goto result page based on the hallticket no i want to fetch all the details.My proble is result.php it showing blank page fetching is not working can anyone help me
index.php:
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style_register.css" />
<link rel="stylesheet" type="text/css" media="all" href="css/responsive.css">
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/validation_script.js"></script>
</head>
<body>
<hr>
<img src="images/banner1.jpg" width="100%" />
<hr>
<section id="container">
<form id="result form" action="result.php" method="POST" enctype="multipart/form-data">
<div>
<label class="desc" id="title1" >Hall Ticket No.</label>
<div>
<input id="name" name="uname" type="text" class="field text fn" value="" size="8" tabindex="1">
<span class="val_name"></span>
</div>
</div>
<div>
<div>
<input type="submit" name="submit_registration" value="Submit" /><input type="reset" name="reset" value="Reset" />
</div>
</div>
</form>
</section>
</body>
</html>
result.php:
<?php
session_start();
if (isset($_SESSION['id'])) {
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style_register.css" />
<link rel="stylesheet" type="text/css" media="all" href="css/responsive.css">
</head>
<body>
<img src="images/banner.jpg" width="100%" />
<section id="container">
<?php
include "../db.php";
$hallticket = $_REQUEST["uname"];
$query = mysql_query("SELECT * FROM results where Hall_Ticket_No='$hallticket'");
$row = mysql_fetch_array($query);
?>
<div id="title" align="center"><h3>Exam Results</h3></div>
<div id="tab">
<table align="center">
<tr><td><b>HallTicketNo</b></td><td> : <?php echo $row['HallTicketNo'];?></td></tr>
<tr><td><b>RNO</b></td><td> : <?php echo $row['RNO'];?></td></tr>
<tr><td><b>FirstName</b></td><td> : <?php echo $row['FirstName'];?></td></tr>
<tr><td><b>LastName</b></td><td> : <?php echo $row['LastName'];?></td></tr>
<tr><td><b>ClassID</b></td><td> : <?php echo $row['ClassID'];?></td></tr>
<tr><td><b>ClassName</b></td><td> : <?php echo $row['ClassName'];?>
<tr><td><b>ExamID</b></td><td> : <?php echo $row['ExamID'];?></td></tr>
<tr><td><b>ExamName</b></td><td> : <?php echo $row['ExamName'];?></td></tr>
<tr><td><b>ClassResult</b></td><td> : <?php echo $row['ClassResult'];?></td></tr>
<tr><td></td></tr>
</table>
<br>
<div id="sign" align="right"><img src="images/sign.png" height=100 width=80></div>
<br>
<center><input type="button" value="home" /></center>
</div>
</section>
</body>
</html>
<?php
}
?>
Than you

In index.php you are not starting session and not registering session id. That is why the if condition of your result.php is not executing.
In index.php do add this line.
<?php
session_start();
$_SESSION['id']= "1213"; //your id here
?>

Related

Beginner PHP $_POST issue (input type?)

I'm trying to figure out what's going wrong here. I'm trying to post a question number to the page, so as you answer questions it increments up. For some reason I can't get it to post, the only way I got it to work was when I include var_dump($q_num); after the part where I increment the $q_num variable.
I'm assuming this is something very simple but I'm not sure what it is. Any help would be appreciated, thanks!
I know I should sanitize the input, and I've tried a FILTER
<?php
include('inc/quiz.php');
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Math Quiz: Addition</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<?php
if (isset($_POST['page'])){
$q_num = (int)$_POST['page'];
} else {
$q_num = 1;
}
$p_num = 10;
?>
<?php var_dump($q_num);?>
<div class="container">
<div id="quiz-box">
<p class="breadcrumbs">Question #<?= $q_num;?> of <?= $p_num;?></p>
<p class="quiz">What is <?php
?> </p>
<form action="index.php" method="POST">
<input type="hidden" name="page" value="<?php ($q_num+1);?>" />
<input type="submit" class="btn" name="answer" value="135" />
<input type="submit" class="btn" name="answer" value="125" />
<input type="submit" class="btn" name="answer" value="115" />
</form>
</div>
</div>
</body>
</html

500 Error When Attempting to Echo Form data in PHP

I am getting an error page from the server when trying to view my test.php page. Everything on the page loads fine if I remove the php tags.
I am getting an "http error 500" with the following code:
<!doctype HTML>
<html>
<head>
<meta charset="UTF-8">
<Title>Test</Title>
<link rel="stylesheet" type="text/css" href="/CSS/default.css">
</head>
<body>
<?php
echo "<form>
<input type="hidden" name="uid" value="Anonymous">
<input type="hidden" name="date" value='".date()."'>
<textarea name="Message"></textarea><br>
<button type="submit" name="submit">Comment</button>
</form>";
?>
</body>
</html>
Or even strip out most of the echo/print
<!doctype HTML>
<html>
<head>
<meta charset="UTF-8">
<Title>Test</Title>
<link rel="stylesheet" type="text/css" href="/CSS/default.css">
</head>
<body>
<form>
<input type="hidden" name="uid" value="Anonymous">
<input type="hidden" name="date" value="<?php print(date()); ?>">
<textarea name="Message"></textarea><br>
<button type="submit" name="submit">Comment</button>
</form>
</body>
</html>
```
<?php
echo '<form>
<input type="hidden" name="uid" value="Anonymous">
<input type="hidden" name="date" value="'.date().'">
<textarea name="Message"></textarea><br>
<button type="submit" name="submit">Comment</button>
</form>';
?>
```
this should work.
Use the following:-
<!doctype HTML>
<html>
<head>
<meta charset="UTF-8">
<Title>Test</Title>
<link rel="stylesheet" type="text/css" href="/CSS/default.css">
</head>
<body>
<?php
echo "<form>
<input type=\"hidden\" name=\"uid\" value=\"Anonymous\">
<input type=\"hidden\" name=\"date\" value='".date()."'>
<textarea name=\"Message\"></textarea><br>
<button type=\"submit\" name=\"submit\">Comment</button>
</form>";
?>
</body>
</html>

My $_POST and $_GET dont work

I tried doing an isset($_POST['btnSubmit']. It gives me nothing so tried to var_dump it. It sais itis empty both before and after i click the button . I even tried to print_r it like this print_r($_POST['btnSubmit']);. What it gives me is:
Undefined index: btnSubmit in
Same thing happens if I use $_GET, $_SESSION , $_COOKIE.
Here is the .tpl file:
<html lang="sv">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="passwordRetrivalStyle.css">
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script src="skriptRetrival.js"></script>
<title>{$title}</title>
</head>
<body>
<header><img src="arrow-back.svg" alt="arrow-back.svg" onclick="goBackFunction()" id="arrow-back"></header>
<div id="content">
<form method="post" action="passwordRetrival.inc.php">
<center><span id="headText">{$headText}</span><br/><br/></center>
<center><span id="smallText">{$smallText}</span></center><br/>
<center><input type="text" name="txtForgot" class="txtForgot" placeholder="Email" />
<br/><br/><br/>
</center>
<center><input type="submit" name="btnSubmit" value="Retrieve Password" class="forgotSubmit" /></center>
<center><input type="submit" name="btnDone" value="Ok, got it" class="newButtonFinished" /></center>
<br/><br/>
<center><div id="opsMSG"></div></center>
<center><div id="errorMsg"></div></center>
</form>
</div>
</body>
</html>

jquery form inserting with php

please help find the sourse of my codes issue...when I click request the page just refreshes with all the data gone but nothing is inserted into the db...
here is the image of the db and the code! what do I need to change to be able to insert the data along with the username of the logged in user?
![the database]http://imgur.com/t0DrlHH
#user1151316 I made the changes and here is the code removing the pointless comments...the data is not being inserted and after submitting I get a blank screen...
<?php
//require_once 'includes/dbconnect.php';
session_start();
if (isset($_POST["request"]))
{
//print_r($_POST);die;
//take care of injections
$service = mysqli_real_escape_string($link,$_POST['service']);
$service_details = mysqli_real_escape_string($link,$_POST['service_details']);
$duedate = mysqli_real_escape_string($link,$_POST['duedate']);
$postdate = mysqli_real_escape_string($link,$_POST['postdate']); //READ ONLY DATE POST
// Insert data into mysql + LOGGED IN USERS USERNAME TO BE INSERTED
$sql = "INSERT INTO serviceposts VALUES ('".$_SESSION["username"]."','".$service."', '".$service_details."', '".$duedate."', '".$postdate."')";
$result= $link -> query($sql) or die (mysqli_error($link));
echo "($result)";
// if successfully insert data into database, displays message "Successful".
if($result){
echo "request post success!";
echo'<script>window.location="http://localhost/Project2/User.php#viewrequests";</script>';
}
else {
echo "Possible data input error";
}
$link->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="includes/js/modernizr.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="jqueryAssets/jquery.mobile.icons.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/Mobi~Style~Me.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.icons-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.datepicker.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
body,td,th {
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
color: #303;
}
body {
background-image: url();
}
</style>
<link href="jqueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
a {
font-weight: bolder;
}
</style>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="jqueryAssets/jquery-ui.min.js"></script>
<script src="jqueryAssets/jquery-2.1.1.min.js"></script>
<script src="jqueryAssets/jquery.mobile-1.4.5.min.js"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.dialog.custom.min.js"></script>
<script src="jqueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.datepicker.custom.min.js" type="text/javascript"></script>
<title>MyITjobs</title>
<meta charset="utf-8">
</head>
<body>
<div data-role="page" id="servicerequest" data-theme="c">
<div data-role="header" data-add-back-btn="true"><h4>IT~Service Request</h4></div>
<span align="center"><?php if (isset($_SESSION["username"]))
{
echo "".$_SESSION["username"]."";
}
?>
</span>
<div data-role="content" class="ui-field-contain" align="center" data-content-theme="c">
<form style="align-items:justify" method="post" action="" id="servicerequest">
<input type="hidden" name="service" id="selected_service"/>
<span>
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false" onchange="onchangeservice()">
<option selected="selected" class="ui-selectmenu-placeholder">IT-Services</option>
<option value="service1" id="MobileApps">Mobile Apps Development</option>
<option value="service2" id="WebDev">Website Development</option>
<option value="service3" id="Programming">Programming</option>
</select>
</span>
<br>
<span>
<div data-role="fieldcontain">
<label for="service_details">IT~Service Request Details</label>
<textarea name="service_details" cols="35" rows="6" id="service_details" placeholder="Input Request details"></textarea>
</div>
</span>
<span>
<label for="duedate">Set Due Date:</label>
<input type="datetime-local" required name="duedate" id="duedate" data-mini="true">
</span>
<br>
<span>
<label for="datetime-local">Request Date</label>
<DateTime id="postdate" data-mini="true">
<?php
$postdate = date("Y-m-d, H:i");
echo "$postdate";
?>
</span>
<input type="hidden" name="postdate" value="<?php echo $postdate; ?>"/>
<br>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<button type="submit" data-icon="check" data-iconshadow="true" data-iconpos="left" id="request" name="request">Request</button></div>
<div class="ui-block-b">
<button type="reset" data-icon="delete" data-iconshadow="true" data-iconpos="left">Cancel</button>
</div>
</fieldset>
<script>
function onchangeservice()
{
var service_option = $( "#service option:selected" ).text();
$('#selected_service').val(service_option);
}
</script>
</form>
</div>
<div data-role="footer" data-theme="c" align="center">
</div>
</div>
</body>
</html>
Do below steps to resolve the issue :
Add a new hidden field
<input type="hidden" name="service" id="selected_service"/>
Add onchange function to select box as
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false" onchange="onchangeservice()">
Replace your script into function
function onchangeservice()
{
var service_option = $( "#service option:selected" ).text();
$('#selected_service').val(service_option);
}
Full code will look like :
`<?php
require_once 'includes/dbconnect.php';
session_start();
//require_once 'includes/dbconnect.php';
/* if (isset($_SESSION["username"]) && !empty($_SESSION["username"])){
echo "".strtoupper($_SESSION['username'])."(Sign out)"; }else{
echo "Sign In";
} */
if (isset($_POST["request"]))
{
//print_r($_POST);die;
//take care of injections
$service = mysqli_real_escape_string($link,$_POST['service']);
$service_details = mysqli_real_escape_string($link,$_POST['service_details']);
$duedate = mysqli_real_escape_string($link,$_POST['duedate']);
$postdate = mysqli_real_escape_string($link,$_POST['postdate']); //READ ONLY DATE POST
// Insert data into mysql + LOGGED IN USERS USERNAME TO BE INSERTED
$sql = "INSERT INTO serviceposts VALUES ('".$_SESSION["username"]."','".$service."', '".$service_details."', '".$duedate."', '".$postdate."')";
$result= $link -> query($sql) or die (mysqli_error($link));
echo "($result)";
// if successfully insert data into database, displays message "Successful".
if($result){
echo "request post success!";
echo'<script>window.location="http://localhost/Project2/User.php#viewrequests";</script>';
// header('Location: ../User.php?success=1');
}
else {
echo "Possible data input error";
//header('Location: ../user.php?error=1');
}
$link->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="includes/js/modernizr.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="jqueryAssets/jquery.mobile.icons.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/Mobi~Style~Me.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.icons-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.datepicker.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
body,td,th {
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
color: #303;
}
body {
background-image: url();
}
</style>
<link href="jqueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
a {
font-weight: bolder;
}
</style>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="jqueryAssets/jquery-ui.min.js"></script>
<script src="jqueryAssets/jquery-2.1.1.min.js"></script>
<script src="jqueryAssets/jquery.mobile-1.4.5.min.js"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.dialog.custom.min.js"></script>
<script src="jqueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.datepicker.custom.min.js" type="text/javascript"></script>
<title>MyITjobs</title>
<meta charset="utf-8">
</head>
<body>
<div data-role="page" id="servicerequest" data-theme="c">
<div data-role="header" data-add-back-btn="true"><h4>IT~Service Request</h4></div>
<span align="center"><?php if (isset($_SESSION["username"]))
{
echo "".$_SESSION["username"]."";
}
?>
</span>
<div data-role="content" class="ui-field-contain" align="center" data-content-theme="c">
<form style="align-items:justify" method="post" action="" id="servicerequest">
<input type="hidden" name="service" id="selected_service"/>
<span>
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false" onchange="onchangeservice()">
<option selected="selected" class="ui-selectmenu-placeholder">IT-Services</option>
<option value="service1" id="MobileApps">Mobile Apps Development</option>
<option value="service2" id="WebDev">Website Development</option>
<option value="service3" id="Programming">Programming</option>
</select>
</span>
<br>
<span>
<div data-role="fieldcontain">
<label for="service_details">IT~Service Request Details</label>
<textarea name="service_details" cols="35" rows="6" id="service_details" placeholder="Input Request details"></textarea>
</div>
</span>
<span>
<label for="duedate">Set Due Date:</label>
<input type="datetime-local" required name="duedate" id="duedate" data-mini="true">
</span>
<br>
<span>
<label for="datetime-local">Request Date</label>
<DateTime id="postdate" data-mini="true">
<?php
$postdate = date("Y-m-d, H:i");
echo "$postdate";
?>
</span>
<input type="hidden" name="postdate" value="<?php echo $postdate; ?>"/>
<br>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<button type="submit" data-icon="check" data-iconshadow="true" data-iconpos="left" id="request" name="request">Request</button></div>
<div class="ui-block-b">
<button type="reset" data-icon="delete" data-iconshadow="true" data-iconpos="left">Cancel</button>
</div>
</fieldset>
<script>
function onchangeservice()
{
var service_option = $( "#service option:selected" ).text();
$('#selected_service').val(service_option);
}
</script>
</form>
</div>
<div data-role="footer" data-theme="c" align="center">
</div>
</div>
</body>
</html>`
You have to do lots of fixes.
You have not added any name attribute to all the input types so they were not posting.
You should write code much indented and clean so that you can find out the issues.
Don't include files multiple times.
Remove unwanted commented code.
Please try below code :
<?php
require_once 'includes/dbconnect.php';
session_start();
//require_once 'includes/dbconnect.php';
/* if (isset($_SESSION["username"]) && !empty($_SESSION["username"])){
echo "".strtoupper($_SESSION['username'])."(Sign out)"; }else{
echo "Sign In";
} */
if (isset($_POST["request"]))
{
//take care of injections
$service = mysqli_real_escape_string($link,$_POST['service']);
$service_details = mysqli_real_escape_string($link,$_POST['service_details']);
$duedate = mysqli_real_escape_string($link,$_POST['duedate']);
$postdate = mysqli_real_escape_string($link,$_POST['postdate']); //READ ONLY DATE POST
// Insert data into mysql + LOGGED IN USERS USERNAME TO BE INSERTED
$sql = "INSERT INTO serviceposts VALUES ('".$_SESSION["username"]."','".$service."', '".$service_details."', '".$duedate."', '".$postdate."')";
$result= $link -> query($sql) or die (mysqli_error($link));
echo "($result)";
// if successfully insert data into database, displays message "Successful".
if($result){
echo "request post success!";
echo'<script>window.location="http://localhost/Project2/User.php#viewrequests";</script>';
// header('Location: ../User.php?success=1');
}
else {
echo "Possible data input error";
//header('Location: ../user.php?error=1');
}
$link->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="includes/js/modernizr.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="jqueryAssets/jquery.mobile.icons.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/Mobi~Style~Me.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.icons-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.datepicker.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
body,td,th {
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
color: #303;
}
body {
background-image: url();
}
</style>
<link href="jqueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
a {
font-weight: bolder;
}
</style>
<script src="jqueryAssets/jquery-1.11.1.min.js"></script>
<script src="jqueryAssets/jquery-ui.min.js"></script>
<script src="jqueryAssets/jquery-2.1.1.min.js"></script>
<script src="jqueryAssets/jquery.mobile-1.4.5.min.js"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.dialog.custom.min.js"></script>
<script src="jqueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.datepicker.custom.min.js" type="text/javascript"></script>
<title>MyITjobs</title>
<meta charset="utf-8">
</head>
<body>
<div data-role="page" id="servicerequest" data-theme="c">
<div data-role="header" data-add-back-btn="true"><h4>IT~Service Request</h4></div>
<span align="center"><?php if (isset($_SESSION["username"]))
{
echo "".$_SESSION["username"]."";
}
?>
</span>
<div data-role="content" class="ui-field-contain" align="center" data-content-theme="c">
<form style="align-items:justify" method="post" action="" id="servicerequest">
<span>
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false">
<option selected="selected" class="ui-selectmenu-placeholder">IT-Services</option>
<option value="service1" id="MobileApps">Mobile Apps Development</option>
<option value="service2" id="WebDev">Website Development</option>
<option value="service3" id="Programming">Programming</option>
</select>
</span>
<br>
<span>
<div data-role="fieldcontain">
<label for="service_details">IT~Service Request Details</label>
<textarea name="service_details" cols="35" rows="6" id="service_details" placeholder="Input Request details"></textarea>
</div>
</span>
<span>
<label for="duedate">Set Due Date:</label>
<input type="datetime-local" required name="duedate" id="duedate" data-mini="true">
</span>
<br>
<span>
<label for="datetime-local">Request Date</label>
<DateTime id="postdate" data-mini="true">
<?php
$postdate = date("Y-m-d, H:i");
echo "$postdate";
?>
</span>
<input type="hidden" name="postdate" value="<?php echo $postdate; ?>"/>
<br>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<button type="submit" data-icon="check" data-iconshadow="true" data-iconpos="left" id="request" name="request">Request</button></div>
<div class="ui-block-b">
<button type="reset" data-icon="delete" data-iconshadow="true" data-iconpos="left">Cancel</button>
</div>
</fieldset>
<script>
$( "#service option:selected" ).text();
</script>
</form>
</div>
<div data-role="footer" data-theme="c" align="center">
</div>
</div>
</body>
</html>

PHP code not Re-directing

what is the problem in this code...??? it is not redirecting to the other page but stay on the login.php page (Blank Page)... Database are all correct...
can someone help me on this code...
your help is much appreciated...
<?
require_once('include/config.php');
require_once('include/functions.php');
session_start();
session_destroy();
$message="";
$Login=$_POST['Login'];
if($Login){ // If clicked on Login button.
$username=$_POST['username'];
$md5_password=md5($_POST['password']); // Encrypt password with md5() function.
mysql_select_db("$db", $con);
$result=mysql_query("select * from staff where stf_username='$username' and stf_password='$md5_password'");
$sql =mysql_query("select stf_level from staff where stf_username='$username'");
if(mysql_num_rows($result)!='0'){ // If match.
session_register("username");
while($row = mysql_fetch_array($sql))
{
//echo $row['level'] . " ";
if($row['stf_level'] == 1){
header("location:admin/index.php");
}
elseif($row['stf_level'] == 2){
header("location:cashier/index.php");
}
elseif($row['stf_level'] == 3){
header("location:waiter/index.php");
}
elseif($row['stf_level'] == 4){
header("location:kitchen/index.php");
}
}
//header("location:main.php"); // Re-direct to main.php
exit;
}else{ // If not match.
$message="--- Incorrect Username or Password ---";
}
} // End Login authorize check.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="description" content="Description" />
<meta name="keywords" content="Keywords" />
<meta name="author" content="Aafrin" />
<title>iCafe Login</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/keyboard.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/keyboard.js"></script>
</head>
<body>
<div id="wrapper">
<div id="loginPanel">
<img class="image" alt="" src="images/logo.png" width="220" height="120" />
<div id="error"><? echo $message; ?></div>
<form id="form" name="form" method="post" action="<? echo $PHP_SELF; ?>">
<label>Username :</label>
<input type="text" name="username" class="keyboardInput" />
<label>Password :</label>
<input type="password" name="password" class="keyboardInput" />
<input name="Login" type="submit" id="Login" value="Login" class="submit" />
<!--
<input type="submit" value="Submit" name="submit" class="submit" />
-->
</form>
<div id="footer">
XYZ © 2012 - All Rights Reserver | Powered By Kesavan
</div>
</div>
<!--
<div id="details">
<p>Login Details</p>
Admin : admin
<br />
Waiter : waiter
<br />
Kitchen : kitchen
<br />
Cashier : cash
</div>
-->
</body>
</html>
try #header("") may be you have an error. Why dont you save all the location in a variable and pass the variable to the header function?
if($x=1){$loc="admin/index.php"}
if($x=2){$loc="staff/index.php"}
if($x=3){$loc="manager/index.php"}
#header('location:$loc')
i think you should put space after the :
it will be like
header("location: cashier/index.php");

Categories