i would like to create php login form but the problem is the form doesnt do anything -
<?php require_once("nocache.php"); ?>
-
-
<?xml version="1.0" encoding="UTF-8"?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
<head>
-
<title>login.php</title>
-
<?php
-
if(isset($_POST['Submit']))
-
if (empty($id) || empty($pword)){
-
header("location: login.php");
-
}else{
-
$conn = mysql_connect("localhost", "TWAassign2", "student");
-
if(!$conn){
-
die('Conection could not be opened: ' . mysql_error());
-
}
-
$db_selected = mysql_select_db('acadcredit', $conn);
-
$sql = "SELECT staffID, accessLevel FROM staff WHERE id = '$id' AND password = '$pword'";
-
$rs = mysql_query($sql, $conn);
-
if (mysql_num_rows($rs)> 0 ) {
-
session_start();
-
$_SESSION["who"] = $id;
-
$_SESSION["level"] = mysql_result($rs,0,"level");
-
header("location: selectView.php");
-
}else{
-
header("location: login.php");
-
}
-
}
-
?>
-
-
</head>
-
<body>
-
<form method="post" action="login.php">
-
<h1> Welcome to Login Page </h1>
-
<h2> Please enter Your Staff ID and password- Thanks</h2>
-
<p>Staff ID <input type="text" name="ID" /><br/>
-
Password <input type="password" name="pass" /></p>
-
<p>
-
<?php
-
if(isset($_POST['ID'])){
-
$id = $_POST["ID"];
-
$pword = $_POST["pass"];
-
}
-
?>
-
-
<input type="submit" value="login" />
-
<input type="reset" value="Reset" /></p>
-
</form>
-
</body>
-
</html>
-
why isnt working
thanks
8 2266 -
-
<?php session_start();
-
// have to initialised session_start(); top of the page
-
?>
-
<?xml version="1.0" encoding="UTF-8"?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
<head>
-
<title>login.php</title>
-
<?php
-
if(isset($_POST['Submit'])){
-
-
$id= $_POST['ID'];
-
$pword= $_POST['pass'];
-
-
}
-
if (empty($id) || empty($pword)){
-
header("location: login.php");
-
}else{
-
$conn = mysql_connect("localhost", "TWAassign2", "student");
-
if(!$conn){
-
die('Conection could not be opened: ' . mysql_error());
-
}
-
$db_selected = mysql_select_db('acadcredit', $conn);
-
$sql = "SELECT staffID, accessLevel FROM staff WHERE id = '$id' AND password = '$pword'";
-
$rs = mysql_query($sql, $conn);
-
if (mysql_num_rows($rs)> 0 ) {
-
session_start();
-
$_SESSION["who"] = $id;
-
$_SESSION["level"] = mysql_result($rs,0,"level");
-
header("location: selectView.php");
-
}else{
-
header("location: login.php");
-
}
-
}
-
?>
-
-
</head>
-
<body>
-
<form method="post" action="login.php">
-
<h1> Welcome to Login Page </h1>
-
<h2> Please enter Your Staff ID and password- Thanks</h2>
-
<p>Staff ID <input type="text" name="ID" /><br/>
-
Password <input type="password" name="pass" /></p>
-
<p>
-
<!-- this pice of code goes top of the page then tou check $_POST['submit'] when you submit the page then passing $id and $pword would be
-
initialised,
-
-
-->
-
<?php
-
/*
-
if(isset($_POST['ID'])){
-
$id = $_POST["ID"];
-
$pword = $_POST["pass"];
-
}*/
-
?>
-
-
<input type="submit" value="login" />
-
<input type="reset" value="Reset" /></p>
-
</form>
-
</body>
-
</html>
-
-
-
i did what you said but still doesnt do anything not giving error or goes to next page and doesnt submit to itself so whats wrong with it
try this and if any error come mention that -
<?php session_start();
-
// have to initialised session_start(); top of the page
-
?>
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
<head>
-
<title>login.php</title>
-
</head>
-
<body >
-
<br><br>
-
-
-
<?
-
-
if(isset($_POST['submit'])){
-
-
$id= $_POST['ID'];
-
$pword= $_POST['pass'];
-
/echo "password".$pword;
-
//echo "id".$id;
-
}
-
if (empty($id) || empty($pword)){
-
header("location: login.php");
-
}else{
-
$conn = mysql_connect("localhost", "TWAassign2", "student");
-
if(!$conn){
-
die('Conection could not be opened: ' . mysql_error());
-
}
-
$db_selected = mysql_select_db('acadcredit', $conn);
-
$sql = "SELECT staffID, accessLevel FROM staff WHERE id = '$id' AND password = '$pword'";
-
$rs = mysql_query($sql, $conn);
-
if (mysql_num_rows($rs)> 0 ) {
-
-
$_SESSION["who"] = $id;
-
$_SESSION["level"] = mysql_result($rs,0,"level");
-
header("location: selectView.php");
-
}else{
-
header("location: login.php");
-
}
-
}
-
?>
-
<!--=============================================================================-->
-
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
-
<h1> Welcome to Login Page </h1>
-
<h2> Please enter Your Staff ID and password- Thanks</h2>
-
<p>Staff ID <input type="text" name="ID" /><br/>
-
Password <input type="password" name="pass" /></p>
-
-
<input type="submit" value="login" />
-
<input type="reset" value="Reset" /></p>
-
</form>
-
-
-
-
</body>
-
</html>
-
-
-
-
the error was no input satisfied and then page not found why? and i have this at the top of page0 ) { $_SESSION["who"] = $id; $_SESSION["level"] = mysql_result($rs,0,"level"); header("location: selectView.php"); }else{ header("location: login.php"); } } ?> please help thanks
i realy need help to create the login page as soon as possible please help
thanks
creating a login is really simple: - <?
-
if(!isset($_SESSION)){
-
session_start();
-
}
-
-
if($_SERVER['REQUEST_MEHOD']='post'){
-
$conn = mysql_connect("myServer","root","");
-
mysql_select_db("myDB");
-
-
$result = mysql_query("SELECT * FROM users WHERE user = ".$_POST['username']." AND password = ".$_POST['passwd'],$conn);
-
-
if(mysql_num_rows($result) == 1){
-
$_SESSION['user']=$_POST['username'];
-
$_SESSION['pw']=$_POST['passwd'];
-
-
header('location: anotherpage.php');
-
} else {
-
echo 'failed to login';
-
}
-
}
-
-
mysql_free_result($result);
-
mysql_close($conn);
-
?>
-
-
<form method='post'>
-
<input type='text' id='username' name='username' />
-
<input type='password' id='passwd' name='passwd' />
-
<input type='submit' />
-
</form>
on all other pages you use exacly the same code (appart from the form) but instead you use your session variables in your query. also, when you see the SQLquery returns more then one or no row, you use - header('location: login.php');
in your if structure
what did you do wrong:
your first try came very close. you only forgot that php is executed before page loads so this - <?php
-
if(isset($_POST['ID'])){
-
$id = $_POST["ID"];
-
$pword = $_POST["pass"];
-
}
-
?>
needs to be checked in the beginning instead of at the end of your page.
hope that helped
jan
i did what you said and i have these errors Notice: Undefined index: username in D:\wwwroot\twa09\twa015\assignment2\login1.php on line 18
Notice: Undefined index: passwd in D:\wwwroot\twa09\twa015\assignment2\login1.php on line 18
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wwwroot\twa09\twa015\assignment2\login1.php on line 20
failed to login
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in -
<?xml version="1.0" encoding="UTF-8"?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<head>
-
<title>login.php</title>
-
<?php
-
if(!isset($_SESSION)){
-
session_start();
-
}
-
-
if($_SERVER['REQUEST_METHOD']='post'){
-
$conn = mysql_connect("localhost", "TWAassign2", "student");
-
$db_selected = mysql_select_db('acadcredit', $conn);
-
-
-
$result = mysql_query("SELECT staffName accessLevel FROM users WHERE staffID= ".$_POST['username']." AND password = ".$_POST['passwd']);
-
-
if(mysql_num_rows($result) == 1){
-
$_SESSION['user']=$_POST['username'];
-
$_SESSION['pw']=$_POST['passwd'];
-
-
header('location: selectView.php');
-
} else {
-
echo 'failed to login';
-
}
-
}
-
-
mysql_free_result($result);
-
mysql_close($conn);
-
?>
-
</head>
-
<body>
-
<form method='post'>
-
<p><input type='text' id='username' name='username' /> <br/>
-
<input type='password' id='passwd' name='passwd' /></p>
-
<p> <input type='submit' /> </p><input type="reset" value="Reset" />
-
</form>
-
</body>
-
</html>
-
i need help please
ok my fault i think. try this: - if($_SERVER['REQUEST_METHOD'] == 'post'){
i forgot to use double 'equals' :S
Sign in to post your reply or Sign up for a free account.
Similar topics
by: koolyio |
last post by:
Hey, could you please tell me what is wrong with my login script. I
just started learning php.
CODE:
login.php
<?
session_start();
header("Cache-Control: private");
?>
|
by: Simon |
last post by:
Hi,
I have a Login.php page that logs the user in and out.
I has two forms within the page, (depending on what we are trying to do),
either one to log in or out.
The form calls itself using a...
|
by: Tom Jones |
last post by:
Hi,
I am using the HttpWebRequest and HttpWebResponse classes to pull
information from a web server on the internet.
I have an account on one of the webservers that I need to log into...
|
by: Beginner |
last post by:
I know this is an old question, but searching all over the internet plus
several MS security conferences, still haven't got a straight anwser.
Basically, the login.aspx is on one dedicated server...
|
by: nicholas |
last post by:
Hi,
Got an asp.net application and I use the "forms" authentication mode defined
in the web.config file.
Everything works fine.
But now I would like to add a second, different login page for...
|
by: IdleBrain |
last post by:
Hello All:
I used a Login control to authenticate a user to login. The problem is
that when I login with good username & password, the login view would
say that the login was successful.
But...
|
by: AppleBag |
last post by:
I'm having the worst time trying to login to myspace through code. Can
someone tell me how to do this? Please try it yourself before replying,
only because I have asked this a couple of times in...
|
by: tolkienarda |
last post by:
Hi all
I work for a small webdesign company and we have remote hosting. i built a mysql database with phpmyadmin on the server. i then downloaded and modified a php login page. i am continuing to...
|
by: satishknight |
last post by:
Hi,
Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
|
by: Apostle |
last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |