tutorial for php and forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anmol
Forum Newbie
Posts: 7
Joined: Sat Mar 06, 2004 7:25 pm

tutorial for php and forms

Post by anmol »

tutorial
Last edited by anmol on Sun Mar 14, 2004 11:23 pm, edited 2 times in total.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

if you dont want to intergrate any databases/anything, how do you plan on storing the users name n password?

Code: Select all

<?php
<form action=log.php method=POST>
<input type=text name=var_name>
<input type=text name=var_pass>
<input type=submit value=Submit>

?>
you can echo all the above, and the name in field one would have a variable name $var_name and when the user clicks submit, it will take them to a log.php page where u can use a simple if-statement could validate whether or not a user has type the correct password of not but I cant help you there cause i dont know how u plan on storing the names/passwords.

this is only a idea of how to do it but you need to figure out whtat u want to do to store the names
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

page they login from:

Code: Select all

&lt;html&gt;
&lt;body&gt;
&lt;form action="login.php" method="post"&gt;
Username: &lt;input type="text" name="username"&gt;
Password: &lt;input type="password" name="password"&gt;
&lt;input type="submit" name="submit" value="Login"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
login.php

Code: Select all

<?PHP
session_start();
if($_POST['username']=="anmol" || $_POST['password']=="password"){
$_SESSION['username'] = $_POST['username'];
}
else {
echo "Incorrect Username or Password!";
}
?>
Then on any page you want to check if they're logged in:

Code: Select all

<?PHP
session_start();
if($_SESSION['username']=="anmol"){
//do stuff for logged in ppl
}
else {
//do stuff for ppl that aren't logged in
}
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

that works if you want to assign everyones account as a variable for their name n password(you manually have to create them). if thats what you wanted, i'm sorry for misunderstanding.
anmol
Forum Newbie
Posts: 7
Joined: Sat Mar 06, 2004 7:25 pm

hi

Post by anmol »

no i just wanted to use values assigned to variables as user name and password and no sql database stuff
Post Reply