0
I want to make every user registered on my site have their own profile page, where all users can access it and see the information, such as name, email, date of birth, etc.. But I don’t know two things:
1st: How can I get the information present in the Mysql database table to be displayed? I’ve only got the email, but since I’m a beginner I don’t know exactly how to show with the rest of the information
2º: This is my biggest doubt. How do I create a page for each user? I’ve seen that it doesn’t have to be exactly "physical" but virtual. But I don’t know how I do it.
connect.inc (link to the database)
<?php
$dbservername = 'localhost';
$dbusername = 'root';
$dbpassword= '';
$dbdatabase = 'usuarios';
$connect = mysqli_connect ($dbservername, $dbusername, $dbpassword, $dbdatabase);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
login.php
<?php
include "connect.inc";
session_start ();
if (isset ($_POST['login'])) {
$email = mysqli_real_escape_string ($connect, $_POST['email']);
$senha = mysqli_real_escape_string ($connect, $_POST ['senha']);
$sel_user = "select id from cadastro where email = '$email' AND senha = '$senha'";
$run_user = mysqli_query ($connect, $sel_user);
$row = mysqli_fetch_array($run_user,MYSQLI_ASSOC);
$active = $row ['active'];
$check_user = mysqli_num_rows($run_user);
if ($check_user == 1 ) {
$_SESSION ['login_user'] = $email;
header ("location: capa.php");
}
else {
echo "Email or password is not correct, try again’";
}
}
?>
Session.php
<?php
include ("connect.inc");
session_start ();
$user_check = $_SESSION ['login_user'];
$ses_sql = mysqli_query($connect,"select email from cadastro where email = '$user_check' ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['email'];
if(!isset($_SESSION['login_user'])){
header("location:login.html");
}
?>
Add an addslashes to your post to prevent sql Injection. http://php.net/manual/en/function.addslashes.php
– Maurício Krüger
I was going to answer the other question, but you deleted it, so I’m just going to give you a quick explanation. You first need to have a parameter in the URL indicating which user you will display the profile, example:
perfil.php?usuario=3
, in this case I will take user profile 3, hence just perform a query in your table like this:select * from cadastro where id= '3'
, your query will return an array with all user data of that profile, from there only display the data of it on the page.– Leonardo
Got it. How do I put the parameter in the URL? Thank you for the answer.
– Alexandre Schleder
@lvcs I voted to reopen, if you vote and 3 more then you answer normally
– user28595
@Alexandreschleder just accessing or placing links going to URLS for example:
meusite.com/perfil.php?usuario=3
or using friendly URL can have something likemeusite.com/perfil/3
– Leonardo
@diegofm does not think the question is appropriate, in my view it is wide, because it has several ways of doing, and yet I do not think it is well explained, was going to answer while it was open to help. But I was going to vote to close right after.
– Leonardo
I’m not looking for a specific solution. I just wanted to be told some possible way of doing it. Being a beginner, I can’t be more specific than that, so it gets hard.
– Alexandre Schleder