akhilkumar332 Posted May 12, 2017 Share Posted May 12, 2017 <?php //get values from form in login page $username=$_POST['user']; $password=$_POST['pass']; //connect to the server and select the database $dbserver="localhost"; $dbusername="root"; $dbpassword=""; $dbname=""; $conn=mysqli_connect($dbserver,$dbusername,$dbpassword,$dbname)or die("Connection to Database Server Failed"); //to prevent mysql injection $username=stripcslashes($username); $password=stripcslashes($password); $username=mysqli_real_escape_string($conn, $username); $password=mysqli_real_escape_string($conn, $password); //query the database for user $sql="select * from student where username='$username' and password='$password'"; $result= mysqli_query($conn, $sql); $row=mysqli_fetch_array($result); if($row['username']==$username && $row['password']==$password){ echo "Login Successfull.. Welcome".$row['username']; } else{ echo "Failed to login"; } ?> Link to comment Share on other sites More sharing options...
akhilkumar332 Posted May 12, 2017 Author Share Posted May 12, 2017 problem solved. thank you. Link to comment Share on other sites More sharing options...
benanamen Posted May 12, 2017 Share Posted May 12, 2017 Problem is not solved. Where are you people constantly coming up with this same bad code over and over again? Pretty much everything you could do wrong here, you did. Save yourself troubles and start using PDO. It's how we code in 2017. https://phpdelusions.net/pdo Link to comment Share on other sites More sharing options...
akhilkumar332 Posted May 12, 2017 Author Share Posted May 12, 2017 https://phpdelusions.net/pdo Thank you for the link and i'm already started using pdo. You can now close this thread. Link to comment Share on other sites More sharing options...
Jacques1 Posted May 12, 2017 Share Posted May 12, 2017 You can now close this thread. We don't do that, because sometimes there are additional comments from other users. But you can mark the topic as solved by choosing the best answer and then clicking the “Best Answer” button. Link to comment Share on other sites More sharing options...
benanamen Posted May 13, 2017 Share Posted May 13, 2017 Another thing, do not ever use plain text passwords. Not now, not ever. @Jaques1 has posts in this thread about how to properly use password_hash and password_verify. Search the forum. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.