javascript - Login and Create Account HTML Forms in One Div -
i have 2 forms specified in 1 div. 1 login , other create account. login form works create account button gives login error though call create-account.php file.
below have code.
the login create / account forms
<?php include('login.php'); // includes login script if(isset($_session['login_user'])){ header("location: index.php"); } ?> <!doctype html> <html> <head> <title>login</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="main"> <div id="login"> <h2>login form</h2> <form action="" method="post"> <label>username :</label> <input id="name" name="username" placeholder="username" type="text"> <label>password :</label> <input id="password" name="password" placeholder="**********" type="password"> <input name="submit" type="submit" value=" login "> <span><?php echo $error; ?></span> </form> <form action="create-account.php" method="post" > <input name="submit" type="submit" value=" create user "> </form> </div> </div> </body> </html>
the login.php code given below
<?php include('config2.php'); session_start(); // starting session $error=''; // variable store error message if (isset($_post['submit'])) { if (empty($_post['username']) || empty($_post['password'])) { $error = "username or password invalid"; } else { // define $username , $password $username=$_post['username']; $password=$_post['password']; // create connection $con = mysqli_connect($db_hostname, $db_username, $db_password, $db_database , 3306); // check connection if(mysqli_connect_error()){ die("connection failed: ".$con->connect_error); } // protect mysql injection security purpose $username = stripslashes($username); $password = stripslashes($password); //$username = mysql_real_escape_string($username); //$password = mysql_real_escape_string($password); // retrieve data database $sql="select * admin password='$password' , user_name='$username'"; $result = mysqli_query($con,$sql); $rows = mysqli_num_rows($result); echo sizeof($rows); if($rows == 1) { $_session['login_user']=$username; // initializing session header("location: profile.php"); // redirecting other page } else { $error = "username or password invalid"; } $con->close(); // closing connection } } ?>
the create-account.php file has no codes. suggestion.
Comments
Post a Comment