Trying to create login page using PHP and SQL -
i've been working on website login, , far, have database , register page set up, i'm trying work on login page. i've been trying retrieve data database's table. successfull @ doing on register page make sure there aren't multiple usernames of same name, copied of code , pasted onto page. problem: returns blank. please help... ._. ` khs sitespace
<div id="header"> <a href="index.php"><img src="./images/khslogo2.png" style="margin-left:4;float:left;" width="100" hieght="100"></a> <b>khs<span id="name">sitespace</span></a> <!--img src="./images/menu.png" style="float:right;margin-right:6;" height="100" width="90"--> </div> <div id="content"> <p id="subtitle">login</p> <div style="float:left;height:30%;"> <form action="<?php echo $_server['php_self'];?>" method="post" id="register"><br> username:<br> <input type="text" name="name"><br><br> password:<br> <input type="password" name="pass"> <br><br> <input type="submit" value="confirm"> </form> </div> <div style="float:right;width:50%;border-style:none none none solid; border-color:222222;border-width:4;height:30%;"> <p style="margin-left:20;font-size:20;">output:</p> <p style="margin-left:20;padding-bottom:15;"> <?php error_reporting(0); @ini_set('display_errors', 0); session_start(); $conn = new mysqli("localhost", "shanedrgn", "getting321", "users"); if (!$conn) {die("failure connect");} $name = trim($_post['name']); $pass = trim($_post['pass']); if (empty($name) or empty($pass)) {echo "empty fields";} else { $name = trim($_post['name']); $pass = trim($_post['pass']); echo "check: fields arent empty...";#output echo "testing variables...";#output //error trapping $sql = "select username users username = '$name'"; $data = mysqli_query($conn, $sql); if($record=mysqli_fetch_array($data)) { $nametrap = $record['username']; } $sql = "select address users address = '$address'"; $data = mysqli_query($conn, $sql); if($record=mysqli_fetch_array($data)) { $iptrap = $record['address']; } if ($nametrap == $name) { echo "check: username exists..."; if ($passtrap == $pass) { echo "password correct!"; $_session['user'] = $name; $sql = "select * users username = '$name'"; $data = mysqli_query($conn, $sql); $record=mysqli_fetch_array($data); session_start(); $_session['id'] = $record['id']; echo "<script>alert('you have logged in!')</script>"; sleep(4); header("location: ./index.php"); /* redirect browser */ exit(); } else { echo "password invalid";} } else {echo "that username doesn't exist!";echo $name.";;";echo $nametrap;} } ?> </p></div> </div> </body> </html>`
edit: added missing code
you doing this:
echo "<script>alert('you have logged in!')</script>"; sleep(4); header("location: ./index.php"); /* redirect browser */
i understand, try, can't work. can't set header after sending body-content - using echo.
you should use javascript redirect, after 4 second timeout. use settimeout
, window.location
.
Comments
Post a Comment