Hello everyone!
First,I am new in php coding and my skills are very low.
So,I have problem with id in url.
I think this code is problem
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0 ;
When I click on button “My profile” code under
<a href="profile.php">My profile</a>
PHP shows me wrong data.
Details:
I have html template where php will fetch data and its named profile.php
And I have one “user account” in database named by my site if something goes wrong php will show data from that “account”
And now,when i click on My profile php shows data from ID 0
When I change ID here from 0
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0 ;
To 1
$id = isset($_GET['id']) ? (int)$_GET['id'] : 1 ;
php on profile.php shows my data.
Whenever the ID changes, php will show data from that user who is the ID in the database
I want to change this so that when user ID 1 clicks on profile.php to show him all the data from ID 1
So when user ID 2 clicks on profile.php to show him all the data from ID 2
I hope you understood me, if you are not the best, please tell me to explain a little better, although I think you understand what I want.
You need to decide how you want profile pages to work.
Normally, you would dynamically produce a profile link with the user’s id as a get parameter on the end of it.When you visit your own profile, the user id from the url matches the user id stored in the session login variable, you would query for and display all the profile information, along with the navigation needed to edit values, and allow the form processing code to be executed. If someone visits a profile that is not their own, the user id from the url does not match the session login variable or there is no session login variable, you would query for and display only the ‘public’ parts of the profile information.
An alternative method, where only a logged in user can view their own profile, would be to use a general link, without the id on the end of it, then on the profile page you would require there to be a user id in the session login variable, which you would use to query for and display all the user’s profile information.
Using id=1 was just an example of a query string you could use for the script to get the id.
Of course the number in the string would have to be dynamically placed from the user’s own id.