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");
Related
im trying to make a madlibs kind of game, right now i got everything working besides 1 thing. the output should overwrite the questions instead of showing above the questions. how can i manage to do this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Mad Libs</title>
<link rel="stylesheet" type="text/css" href="MadLibs.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Libre+Baskerville:wght#700&display=swap" rel="stylesheet">
</head>
<body>
<form action="" method="POST">
<h1> MadLibs</h1>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$Input1 = $_POST["Input1"];
$Input2 = $_POST["Input2"];
$Input3 = $_POST["Input3"];
$Input4 = $_POST["Input4"];
echo "here is a test $Input1. here is an other test $Input2 and again an other test
$Input4 test $Input3.";
}else{
<p id="Text">test question <input type="text" required name="Input1" placeholder="Enter your answer.."></p>
<p id="Text">test question <input type="text" required name="Input2" placeholder="Enter your answer.."></p>
<p id="Text">test question<input type="text" required name="Input3" placeholder="Enter your answer.."></p>
<p id="Text">test question <input type="text" required name="Input4" placeholder="Enter your answer.."></p>
<input id="Submit" type="submit" name="submit" value="Send">
</form>
?>
<footer>
<p> A #2021 website</p>
</footer>
</body>
</html>
The end result shows like this but the questions and the input field should be gone when the submit button is pressed
I hav a Php code. It connects with the server and database, but it does not validate my form data with mysql database table. I hav same exact code which executes, but the following does not execute.........
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
include_once 'dbconnect.php';
if(isset($_SESSION['user'])!="")
{
header("Location: welcome.html");
}
if(isset($_POST['Submit']))
{
$name = $_POST['loginName'];
$upass = $_POST['loginPass'];
$res=mysql_query("SELECT * FROM authen WHERE name='$name'");
$row=mysql_fetch_array($res);
if($row['passwrd']==$upass)
{
$_SESSION['user'] = $row['user_id'];
header("Location: welcome.html");
}
else
{
?>
<script>alert('wrong details');</script>
<?php
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- JavaScript includes
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> -->
<script src="assets/js/jquery-1.11.3.min.js"></script>
<script src="assets/js/jquery-ui-1.10.4.js"></script>
<script src="assets/js/script.js"></script>
<meta charset="utf-8" />
<link rel="stylesheet" href="assets/css/styles.css" />
<link rel="stylesheet" href="assets/css/jquery.fancybox.css" />
</head>
<body>
<div id="formContainer">
<form id="login" method="post">
<p id="lgnfrm">Login Form</p>
<input type="text" name="loginName" id="loginName" placeholder="User Name" required />
<input type="password" name="loginPass" id="loginPass" placeholder="password" required />
<input type="submit" name="Submit" id="sub" value="Login" />
</form>
</div>
<footer>
</footer>
</body>
</html>
I hav modified the code as directed but still i get the same response, i.e nothing happens
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
include_once 'dbconnect.php';
if(isset($_SESSION['user']) && $_SESSION['user'] != "")
{
header("Location: welcome.html");
}
if(isset($_POST['Submit']))
{
$name = mysql_real_escape_string($_POST['loginName']);
$upass = mysql_real_escape_string($_POST['loginPass']);
$res=mysql_query("SELECT * FROM authen WHERE name='$name'");
$row=mysql_fetch_array($res);
if($row['passwrd']==md5($upass))
{
$_SESSION['user'] = $row['user_id'];
header("Location: welcome.html");
}
else
{
?>
<script>alert('wrong details');</script>
<?php
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- JavaScript includes
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> -->
<script src="assets/js/jquery-1.11.3.min.js"></script>
<script src="assets/js/jquery-ui-1.10.4.js"></script>
<script src="assets/js/script.js"></script>
<meta charset="utf-8" />
<link rel="stylesheet" href="assets/css/styles.css" />
<link rel="stylesheet" href="assets/css/jquery.fancybox.css" />
</head>
<body>
<div id="formContainer">
<form id="login" method="post">
<p id="lgnfrm">Login Form</p>
<input type="text" name="loginName" id="loginName" placeholder="User Name" required />
<input type="password" name="loginPass" id="loginPass" placeholder="password" required />
<input type="submit" name="Submit" id="sub" value="Login" />
</form>
</div>
<footer>
</footer>
</body>
</html>
isset returns boolean
your code should be
if(isset($_SESSION['user']) && $_SESSION['user'] != "")
{
header("Location: welcome.html");
exit;
}
Or
if(!empty($_SESSION['user']))
{
header("Location: welcome.html");
exit;
}
Do following changes in your first code
if(isset($_SESSION['user']) && !empty($_SESSION['user']))
{
header("Location: welcome.html");
}
hope this helps!!,please comment for further queries
When ever I use this piece of PHP, it makes the webpage blank (white) and does not show anything. Here is my code:
<?php
if(isset($_POST['submit'])){
//
$user = $_POST['username'];
$pwrd = $_POST['pwrd'];
//include database connection
include('../includes/db_connect.php');
if(empty($user) || empty($pwrd)){
echo 'Missing information';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div id="container">
<form action="Login.php" mthod="post">
<p>
<label>Username</label><input type="text" name="username" />
</p>
<p>
<label>Password</label><input type="password" name="pwrd" />
</p>
<input type="submit" name="submit" value="logIn" />
</form>
</div>
</body>
</html>
After testing different pieces of the PHP code, I have noticed only this code make the page blank
if(empty($user) || empty($pwrd)){
echo 'Missing information';
}
?>
Is this possibly something to do with Apache, or is there something wrong with my PHP?
There are following problem:-
your first if bracket is not closed. So closed it.
your form method is not correct. Spelling mistake:-
So the correct code is here :-
<?php
if(isset($_POST['submit'])){
//
$user = $_POST['username'];
$pwrd = $_POST['pwrd'];
//include database connection
include('../includes/db_connect.php');
if(empty($user) || empty($pwrd)){
echo 'Missing information';
}
}// missing
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div id="container">
<form action="Login.php" method="post"> // method is written mthod
<p>
<label>Username</label><input type="text" name="username" />
</p>
<p>
<label>Password</label><input type="password" name="pwrd" />
</p>
<input type="submit" name="submit" value="logIn" />
</form>
</div>
</body>
</html>
Output:- before submit :- http://prntscr.com/74xhb7
After submit :- http://prntscr.com/74xhmm
Note:- the bracket that i said you to close you can close it based on your convinence. Thanks.
Also don't panic with error you seen in second screenshot. It's because i am not having included files at my end.
I have one file, that file is a form for administrator change Username and Password. The file named "change_password.php". Here's the code :
<?php
session_start();
include_once('../config.php');
?>
<head>
<meta charset="UTF-8" />
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> -->
<title>***********</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Login and Registration Form with HTML5 and CSS3" />
<meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="../css/demo.css" />
<link rel="stylesheet" type="text/css" href="../css/style2.css" />
<link rel="stylesheet" type="text/css" href="../css/animate-custom.css" />
</head>
<body>
<div class="container">
<!-- Codrops top bar -->
<div class="codrops-top">
<div class="clr"></div>
</div><!--/ Codrops top bar -->
<header>
</header>
<section>
<div id="container_demo" >
<!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4 -->
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="signup" class="animate form">
<form action="change.php" autocomplete="on" method="post" enctype="multipart/form-data">
<h1>Admin's Profile Account</h1>
<?php
$admin_id = $_GET['id_admin'];
$query = mysql_query("select * from administrator where ID_Admin='$admin_id'");
$data = mysql_fetch_array($query);?>
<p>
<label for="username">Username : </label>
<input id="username" name="username" class="wide" type="text" required="required" value="<?php echo $data['username']; ?>"/>
<input id="username2" name="username2" class="wide" type="hidden" required="required" value="<?php echo $data['username']; ?>"/>
</p>
<p>
<label for="password">New Password :</label><input id="password" name="password" class="wide" type="password" required="required" placeholder="Your password" />
</p>
<p>
<label for="confirm_password">Confirm Password : </label> <input id="confirm_password" name="confirm_password" class="wide" type="password" required="required" placeholder="Confirm your password" />
</p>
<p> </p>
<center><p class="signup button">
<input type="submit" value="Submit" />
</p></center>
</form>
<center>Panel Administrator</center>
</div>
</div>
</section>
</body>
</html>
And I have one action file for changing username and password for Administrator. The file named "change.php". When I try to change username and password, this file only just blank. It didn't redirecting to another page. So where's my mistake? I tried to change the part of if else and another but the result is still the same. Here's my code :
<?php
session_start();
include_once('../config.php');
$ID_Admin = $_POST['admin_id'];
$username = $_POST['username'];
$password = $_POST['password'];
$encrypt = md5($password);
$confirm_pass = $_POST['confirm_password'];
if ($confirm_pass != $password) {
echo" <script language='JavaScript'> alert ('Password doesn't match');</script>";
echo '<script language="JavaScript"> window.location.href ="change_password.php" </script>';
} else {
if($_POST['username'] != $_POST['username2']){
$dup = mysql_query("SELECT username FROM administrator WHERE username='".$_POST['username']."'");
if(mysql_num_rows($dup) >0){
echo"<script language='JavaScript'> alert ('Username already use');</script>";
echo '<script language="JavaScript"> window.location.href ="change_password.php" </script>';
}
} else {
$query = mysql_query("update administrator set username='$username', password='$ecnrypt' where ID_Admin='$ID_Admin'") or die(mysql_error());
print '<script type="text/javascript">';
print 'alert("Profile has changed")';
print '</script>';
print '<script type="text/javascript">';
print "window.location.href='panelAdmin.php'";
print '</script>';}
}
?>
Thank you in advance for your help. I think either the part of "if else" or "script alert" that make this file doesn't work.
you need to escape your single quote so this:
echo" <script language='JavaScript'> alert ('Password doesn't match');</script>";
should be this:
echo" <script language='JavaScript'> alert ('Password doesn\'t match');</script>";
i'm guessing that is why its failing, also make sure your display_error() is enabled, to make sure you're not getting any PHP errors.
Try to use this where you have the redirects, just window.location will do the work for you:
echo '<script language="JavaScript">window.location = "change_password.php"; </script>';
Also, note the semicolon after .php"
There is no formelement in your form with the name admin_id. E.g.
<input type="hidden" name="admin_id" value=5" />
So the array $_POST has no index "admin_id", and thus the error message with the undefined index.
Since your PHP code cannot find value passed via POST, you need to include an input named with admin_id inside your form.
Example:
<input type="hidden" name="admin_id" value="<?php echo $admin_id; ?>" />
That should fix your error about:
Notice: Undefined index: admin_id
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
?>