Tuesday, 9 June 2020

how to register a user

how to register a user
before register a user, u have to check the username is there or not,if there tells other username, password is matched with second time entered passwrod
check logged in or not, if it is not logged in, check they subgmited or not ,if submittd load the data to database, enterd or not, if entered, password match check ,if ok, chek that enteredusernam e in the database,I f not there load the enterd database, after succesfully entered,  reloads into some webpage
<?php
require 'core.php';
use template of core, to use some variables from that page
require 'lesson44.php';
use template of lesson44,  connect to data base
if (loggedin() )
from core php, we can get logged in function, it wil show if it is logged in ,
{echo 'you are already registerd and logged in';}
if it is already registered , it will show it is registered
elseif (!loggedin()){
if it is not loggedin, it will exeute customer have to register
if(isset($_POST['username'])
if they submitted username
&& isset($_POST['password'])
password
&& isset($_POST['pass_again'])
passagain
&& isset($_POST['firstname'])
firstname submitted
&& isset($_POST['secondname'])){
second name also submitted,
$username = $_POST['username'];
if they submitted, store to username variable
$password = $_POST['password'];
$passagain = $_POST['pass_again'];
$firstname = $_POST['firstname'];
$secondname = $_POST['secondname'];
$pass_hash = md5($password);
if(!empty($username)&&!empty($password)&&!empty($passagain)&&!empty($firstname)&&!empty($secondname)){
if entered data is not empty,
if($password != $passagain){echo 'passwords are not matched';}
it will check password is matched or not, if it is matched
else {
$query =" SELECT `username` FROM `users` WHERE `username` = '$username'";
run the query about it compares the entered and already tehre username
// to make unique the username , we have to compare the present username with entered username, then only it wil go to next step
if ($query_run = mysqli_query($mycon, $query)){
run the query against database, after run it filtered some rows
echo $num_rows = mysqli_num_rows($query_run);
find how many rows
if ($num_rows == 1){echo 'username already exists!';}
if u got gretert thean one username, it shows , username already exiists
else if ($num_rows == 0){
if it Is equal to zero,then load the enterd data to database
$query = "INSERT INTO `users` (`id`, `username`, `password`, `firstname`, `surname`) VALUES(NULL, '$username', '$pass_hash','$firstname','$secondname')";
write a query to write into database
if($query_run = mysqli_query($mycon, $query)){
run this query, after saved into database
header('Location: success.php');
reload to success php means, u registered succesffully
}
} }

}


}


else { echo 'all fields are required'; }
if it not enterd  and submit , printthis thing


}
}

?>
<h2> sign up </h2>
<form action="register.php" method="POST" >
username : <br> <input type ="text" name ="username" value="<?php if(isset($username)) {echo $username;}?>"> <br> <br>
value means it is fixed,if password entered not matched,instead of entring so many times , it is best to fix
password: <br> <input type="password" name="password"><br><br>
password again: <br> <input type="password" name="pass_again"><br><br>
username : <br> <input type ="text" name ="firstname" ><br> <br>
secondname: <br> <input type="text" name="secondname"><br><br>
<input type="submit" value="sign up">

</form>
success.php
<?php



?>
<h3> u have succesfully registered </h3>;
<a href="LESSON47.PHP" ><h3> click here to login </h3></a>
if (loggedin() )
{}
elseif (!loggedin()){
if(isset($_POST['username'])
){
if(!empty($username)&&!empty($password)&&!empty($passagain)&&!empty($firstname)&&!empty($secondname)){
if($password != $passagain){echo 'passwords are not matched';}
else {
if ($query_run = mysqli_query($mycon, $query)){
if ($num_rows == 1){echo 'username already exists!';}
else if ($num_rows == 0){}
}
}
}
else { }
}
}













how to use other page require
how to use other pga as  template require
if elseif if else if elseif if 
echo
if isset
$_post
md5
if 
else
select from where
mysqli_query
mysqli_num_rows
if
elseif
insertinto users values
if
header
else

No comments:

Post a Comment