I have a login page whose data is getting stored in database with table name "users". I want to use the inputuser from "users" that I have stored to be shown on all the php files I have created and connected to the same database.
I want to use the value of "users" only which I have used to login the database, so that I can know who is logged in. I am pasting the login page and one another php page for example.
login.php
<?php
$inputuser = $_POST["user"];
$inputpass = $_POST["pass"];
$user = "root";
$password = "";
$database = "ABCD";
$connect = mysql_connect("localhost", $user, $password); // Variable that Initializes connection to database
@mysql_select_db($database) or die("Database not found");
$query = "SELECT * FROM `users` WHERE `user` = '$inputuser'";
$querypass = "SELECT * FROM `users` WHERE `pass` = '$inputpass'";
echo $password;
$result = mysql_query($query) or die(mysql_error());
$resultpass = mysql_query($querypass) or die( mysql_error());
$row = mysql_fetch_array($result);
$rowpass = mysql_fetch_array($resultpass);
$serveruser = $row["user"];
$serverpass = $rowpass["pass"];
if ($serveruser && $serverpass){
if(!$result){
//header('Location: fail.html');
die("Username Name or Password is invalid");
}
echo "<br><center>Database Output</b> </center><br><br> ";
mysql_close();
echo $inputpass;
echo $serverpass;
if($inputpass == $serverpass){
header('Location: home.php');
}
}else {
header('Location: fail.html');
echo "Sorry, bad Login";
}
?>
sample.php
<?php
$taken = "false";
$database = "ABCD";
$password = "";
$username = "root";
// Connect to database
$con = mysql_connect('localhost', $username, $password) or die("Unable to connect database");
@mysql_select_db($database, $con) or die("Unable to connect");
$paper_title = mysql_real_escape_string($_GET['id']);
$query = "SELECT * FROM paper WHERE ptitle = '$paper_title'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
mysql_close();
?>
<div align = "center">
<form method="post" action="updatedata.php" />
<table>
<tr>
<td>Title: </td>
<td><input type="text" name="ptitle" value="<?php echo "$row[ptitle]" ?>"> </td>
</tr>
</table>
<input type ="submit" value ="Update this Information">
</form>
</div>