Advertisement
Guest User

Untitled

a guest
Aug 8th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. session.php
  2. <?php $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("login", $connection); //$db =mysql_select_db("company", $connection); session_start(); $user_check=$_S
  3. ESSION['login_user']; $ses_sql=mysql_query("select username from user where username='$user_check'", $connection); $row=mysql_fetch_assoc($ses_sql); $login_session =$row['username']; if (!isset($login_session)){ mysql_close($connection); header('Location: log.php'); } ?>
  4. login.php
  5. <?php session_start(); $error=''; if (isset($_POST['
  6. submit'])) { if (empty($_POST['username']) || empty ($_POST['password'])){ //$error ="Username or Password is invalid"; ?><script> alert("Username or Password is invalid!"); history.back(); </script><?php } else { $username=$_POST['username']; $password=$_POST['password']; $connection = mysql_connect("
  7. localhost", "root", ""); $username = stripslashes($u
  8. sername); $password = stripslashes($password); $username = mysql_real_escape_string($user
  9. name); $password = mysql_real_escape_string($password); $db = mysql_select_db("login", $connection); $query = mysql_query("select * from user where password='$password' AND username='$username'", $connection); $rows = mysql_num_rows($query); if ($rows == 1) { $_SESSION['login_user']=$username; header("location: index.php"); } else { //$error ="Username or Password is invalid"; ?><script> alert("Username or Password is invalid!"); history.back(); </script><?php } mysql_close($connection); } } ?>
  10. log.php
  11. <?php include('login.php'); if (isset($_SESSION['login_user'])){ header("location: profile.php"); } ?> <html> <head> <title>Login Form in PHP with Session</title> </head> <body align="center"> <div align="center"> <h1><center>Login form For Login</center></h1> <div id="login"> <h2>Login Form</h2> <form action="" method="post"> <label>Username :</label> <input id="name" name="username" placeholder="username" type="text"><br></br> <label>Password :</label> <input id="password" name="password" placeholder="**********" type="password"> <br> </
  12. br> <input name="submit" type="submit" value="Login"> <input name="reset" type ="reset" value="Cancel"> <span> <?php echo $error; ?> </
  13. span><br><br> <a href="insert.html"> CREATE NEW ACCOUNT</a> </form> </div> </div> </body> </html>
  14. create.php
  15. <?php $u=$_GET["txtu"]; $ps=$_GET["txtps"]; $fn=$_GET["txtfn"]; $mn=$_GET["txtmn"]; $ln=$_GET["txtln"]; $bm=$_GET["txtbm"]; $bd=$_GET["txtbd"]; $by=$_GET["txtby"]; $a=$_GET["txta"]; $g=$_GET["txtg"]; $r=$_GET["txtr"]; $ad=$_GET["txtad"]; $con=mysql_connect("localhost","root",""); $db = mysql_select_db("login", $con); $sql="select * from user where username ='$u';"; $rs=mysql_query($sql); $count=mysql_num_rows($rs); if ($u=="" || $ps=="" || $fn=="" || $mn=="" || $ln=="" || $bm=="" || $bd=="" || $by=="" || $a=="" || $g=="" || $r=="" || $ad=="" ){ ?><script> alert("all fields are required!"); history.back(); </script> <?php }else{ if($count==0){ $sql="INSERT INTO user VALUES ('$u','$ps','$fn','$mn','$ln','$bm','$bd','$by',
  16. '$a','$g','$r','$ad');"; mysql_query($sql); ?><script> alert("created!"); location="profile.php"; </script> <?php }else{?> <script> alert("Id already exist!"); history.back(); </script> <?php } }?>
  17. profile.php
  18. <?php include('session.php'); ?> <html> <head> <title>Your Home Page</title> </head> <body> <div> <b><i></i></b> <?php $connection = mysql_connect("localhost", "root", ""); if (!$connection) { die('could not: '. mysql_error()); } mysql_select_db("login",$connection); $result=mysql_query("SELECT * From user where username='$login_session'"); while($row=mysq
  19. l_fetch_array($result)) { ?><div id="gitna"><?php echo "<b>Welcome : </b>",$row['firstname']. " ".$row['middlename']. " ".$row['lastname']; echo "<br/>"; echo "<b>Birth-Day :</b>",$row['birthm
  20. onth']. " ".$row['birthday']. ", ".$row['birthyear']; echo "<br/>"; echo "<b>Age :</b>",$row['age']; echo "<br/>"; echo "<b>Gender :</b>",$row['gender']; echo "<br/>"; echo "<b>Religion :</b>",$row['religi
  21. on']; echo "<br/>"; echo "<b>Address :</b>",$row['address']; echo "<br/>"; ?></div><?php } mysql_close($connection); ?> <b id="logout"><a href="logout.php">Log Out</a></b> <b id="logout"><a href="edit.html">My Database</a></b> </div> </body> </html>
  22. edit.php
  23. <?php $u=$_GET["txtu"]; $ps=$_GET["txtps"]; $fn=$_GET["txtfn"]; $mn=$_GET["txtmn"]; $ln=$_GET["txtln"]; $bm=$_GET["txtbm"]; $bd=$_GET["txtbd"]; $by=$_GET["txtby"]; $a=$_GET["txta"]; $g=$_GET["txtg"]; $r=$_GET["txtr"]; $ad=$_GET["txtad"]; $con=mysql_connect("localhost","root",""); $db = mysql_select_db("login", $con); $sql="select * from user where username ='$u';"; $rs=mysql_query($sql); $count=mysql_num_rows($rs); if ($u=="" || $ps=="" || $fn=="" || $mn=="" || $ln=="" || $bm=="" || $bd=="" || $by=="" || $a=="" || $g=="" || $r=="" || $ad=="" ){ ?><script> alert("all fields are required!"); history.back(); </script> <?php }else{ if($count==0){ $sql="update user set username ='$un', password ='$pw', firstname='$fn', middlename='$mn', birthmonth ='$bm', birthday='$bd' , birthyear='$by' , age='$a' , gender='$g' , religion='$r' , address='$ad' where username='$un' "; mysql_query($sql); ?><script> alert("updated!"); location="edit.php"; </script> <?php }else{?> <script> alert("Id already exist!"); history.back(); </script> <?php } }?> ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement