I would like to display the users data from the table, so once the user has logged in to the website, text shows on the page saying "Welcome (firstname) (lastname)."
The columns for firstname is "Firstname" and lastname is "Lastname". I have tried many different methods, but all of them seem to return errors and I cannot get it to work. If anyone can help, that would be great.
Here is my code:
<html> <head> <title>Landing page</title> <link rel="stylesheet" type="text/css" href="css.css"> </head> <body> <?php /* ESTABLISH FIRST YOUR CONNECTION TO YOUR DATABASE */ $con = new mysqli("localhost", "root", "", "user_login"); /* REPLACE NECESSARY DATA */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if($stmt = $con->prepare("SELECT Username, Password FROM users WHERE Username = ? AND Password = ?")){ $stmt->bind_param("ss",$_POST["username"],$_POST["password"]); $stmt->execute(); $stmt->store_result(); $checklog = $stmt->num_rows; if($checklog > 0){ /* HERE IS YOUR CODE WITH SUCCESSFUL LOGIN */ session_start(); $_SESSION["logged_in"] = "YES"; echo "<h1>You are now logged in</h1>"; echo "<p><a href='secure1.php'>Link to protected file</a></p>"; echo "<p><a href='secure2.php'>Link to protected file #2</a></p>"; } else { /* HERE IS YOUR CODE WITH UNSUCCESSFUL LOGIN */ session_start(); $_SESSION["logged_in"] = "NO"; echo "<h1>You are NOT logged in </h1>"; echo "<p><a href='secure1.php'>Link to protected file</a></p>"; echo "<p><a href='secure2.php'>Link to protected file #2</a></p>"; } $stmt->close(); } ?> <p><a href="public.html">Public Page</a></p> <p><a href="logout.html">Logout</a></p> </body> </html> What is the mistake i am doing and how can i fix it ?
"Welcome (firstname) (lastname)."? and what error you are getting?