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.
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'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
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
I have a very simple HTML form that is supposed to send information to the file written in action attribute via GET but somehow it's transfering the information back to index.php:
index.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Forms Sandbox</h1>
<form acton="process_form.php" method="get">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" />
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="" />
<input type="submit" name="submit_btn" id="submit_btn" value="Submit" />
</form>
</body>
</html>
process_form.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Response Sandbox</h1>
<?php
$username = $_GET["username"];
$email = $_GET["email"];
echo $username . " : " . $email . "<br />";
?>
</body>
</html>
The bizarre aspect is that when I submit the form, the URL shows that it is not even using process_form.php:
http://127.0.0.1/Learning/?username=test&email=x%40test.com&submit_btn=Submit
If I manually change the URL to include process_form.php it seems to be working fine and I get the results I am looking for:
http://127.0.0.1/Learning/process_form.php?username=test&email=x%40test.com&submit_btn=Submit
On my development computer, I'm running EasyPHP 14.1 local WAMP server and thought it might be the root of the problem so I uploaded the files to my website that is running newest PHP on Apache, but the problem still exists there.
What am I doing wrong?
you have a typo error in action; you have given acton. Should be like this:
<form action="process_form.php" method="get">
First thing - you have a typo:
<form action="process_form.php" method="get">
^
The second thing - in my opinion the best method of handling forms is using POST method, not GET, so I would change it to:
<form action="process_form.php" method="post">
and in process_form.php I would use $_POST instead of $_GET
After digging around your question,
Index.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Forms Sandbox</h1>
<form action="process_form.php" method="get">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" />
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="" />
<input type="submit" name="submit_btn" id="submit_btn" value="Submit" />
</form>
</body>
</html>
process_form.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Response Sandbox</h1>
<?php
$username = $_GET["username"];
$email = $_GET["email"];
echo $username . " : " . $email . "<br />";
?>
</body>
</html>
Note: If you will not specify form method, By default it will take GET method. So please make sure action should be perfect.
Above code just copy and paste, it should work perfect.
Ask me for further clarification.
Thanks,
Gauttam
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");