Reputation: 81
I have a php file named profile.php, where in URL if you type mywebsite.com/profile.php you go to your profile, what I would like is for other profiles to show up as link with their ID, for example lets say I want to see Bob's profile, and his ID is 25, I would go to mywebsite.com/profile.php?ID=25 or something like that, how may I achieve that?
Thank you.
GUYS, im having alot of trouble with this, so heres the code I have for profile.php, also please let me know what I should do so when users click on the name it also takes them to profile, having lots of trouble with this guys thank you!!
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] == false) {
header( 'Location: index.php' ) ;
exit;
}
include('get-info.php');
if ($_SESSION['email']) {
}else{
header( 'Location: profile.php' ) ;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="Icon" href="images/ricon.ico" >
<title>
Rate-Away | Profile
</title>
<link href='css.css' rel='stylesheet' type='text/css' />
</head>
<body class='home-body' >
<div class='home-nav-bar'>
<div class='home-nav-bar-content'>
<a href="home.php"><img src='images/rateaway.png' class='home-nav-bar-logo' /></a>
<div class='home-nav-bar-links-container' >
<div class='dropdown'>
<ul>
<li class='nav-options'>
<a href="#" class='options-link' >Options</a>
<ul class='drop-down-options'>
<li><a href="home.php" class='drop-down-links'>Home</a></li>
<li><a href="#" class='drop-down-links'>Profile</a></li>
<li><a href="settings.php" class='drop-down-links'>Settings</a></li>
<li><a href="logout.php" class='drop-down-links'>Logout</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class='home-main-content' >
<div class='profile-current-info'>
<p class='profile-name'> <?php get_info($_SESSION['email'], 'name'); ?> </p>
<img src='<?php get_info($_SESSION['email'], 'profilepic'); ?>' class='profile-pic'/>
<p class='profile-dob' > Born: <?php get_info($_SESSION['email'], 'dob_day'); ?> </p>
<p class='profile-country' > Currently lives in: <?php get_info($_SESSION['email'], 'country'); ?> </p>
<p class='profile-gender' > Gender: <?php get_info($_SESSION['email'], 'gender'); ?> </p>
</div>
<div class='profile-edit-info' >
</div>
</div>
</body>
</html>
Upvotes: 0
Views: 1078
Reputation: 167
Use $_GET
universal variable
Suppose someone opens profile.php?id=25
Then in php tags if you write
$idtoload=$_GET['id'];
$toload
will have value 25.
You can continue with your database connection after this..
Upvotes: 0
Reputation: 21191
Let's assume you have some sort of array of user data:
$people = array(
1 => array('name'=>"Harry", 'id'=>1),
2 => array('name'=>"Sally", 'id'=>2)
);
Then, wherever you are writing out your links:
<a href="/profile.php?ID=<?php echo $people[1]['id'] ?>"><?php echo $people[1]['name'] ?></a>
will give you:
<a href="/profile.php?ID=1">Harry</a>
Obviously, this is a simple and contrived example, but does it make sense what you need to do?
Upvotes: 0
Reputation: 628
In your profile.php code you would grab the id from the url by using
$_GET['id']
Then when your displaying your page...e.g The html part you would check to see if there was an id passed by either using "isset" or checking if id was empty or not and then display the page according to that for example:
<?php
if isset($_GET['id']){
$userid = $_GET['id'];
//CHECK THE DATABASE FOR $USERID NOW BUT MAKE SURE YOU mysql_real_escape_string($userid);
}else {
//print users profile
}
?>
Upvotes: 0
Reputation: 26722
You need to use $_GET['id']
and send data via GET method to profile.php
page
<form action="profile.php" method="GET">
My ID<input type="text" name="id">
<input type="submit" value="submit" />
</form>
Upvotes: 0
Reputation: 10830
In your form tag
<form method='GET' action='profile.php' ...>
...
So when its sent, you can see it at the top the way you want it.
Upvotes: 0