I want to create simple profile system. I want to display data of user from the database on the profile page. I dont want to make setting page. I just simply want to display it.
There are three columns in db right now, Id,username and password. I am adding first name,lastname, about me and about me to database.
I want to improve on my current php page and dont want to create new page. Please give me advice on how can i create simple profile system?
Here is my code of index.php
<?php
session_start();
if(isset($_SESSION['user'])){
header("location: profile.php");
echo "Welcome ".$_SESSION['user']." !";
}
else{
display_form();
}
function display_form(){
?>
<form action="verify.php" method="POST">
Name:<input name = "username" type = "text" />
Pass:<input name = "password" type = "text" />
<input name = "submit" type="submit" />
</form>
<?php
}
?>
My code of profile.php
<?php
session_start();
if (isset($_SESSION['user'])){
$loggeduser = $_SESSION['user'];
echo "Welcome ".$loggeduser." !";
?>
<a href="logout.php"> Log out now! </a>
<?php
//Start displaying profile
}
else
header("location: index.php");
?>
Code of verification page
<?php
session_start();
//Make sql connection and select databases
$database_connect = mysql_connect('localhost','root','');
if(!$database_connect){
die('Could not connect to databse');
}
else{
echo "Connected to database successfully!<br/>";
}
$db_table_connect = mysql_select_db('selftest');
if(!$db_table_connect){
echo "Connection to table failed";
}
else{
echo "Connected successfully to table!<br/><br/>";
}
//Begin with user verifications
if(isset($_POST['submit'])){
$username = $_POST['username'];
$userpass = $_POST['password'];
$sql = "SELECT * FROM users WHERE username = '$username' and password = '$userpass'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if($count == 1){
echo "Successfully logged in!";
$_SESSION['user'] = $username;
header("refresh:5;url=profile.php");
}
else{
echo "Failed to log in!";
header("refresh:5;url=index.php");
}
}