Hi
I have managed to get the page checking if logged in already and redirect to the profile page but the url outputs as
I need to get the userid after = instead of $id
Below is my code from the login page, I am unsure of what I am doing wrong or what I am not doing to get the userid in the url, hope someone can help me please
[CODE]
<?php
session_start();
ob_start();
if (!empty($_SESSION[‘username’])) {
header(‘Location:affiliate-profile.php?id=$id’);
exit;
}
?>
<?php
$title = “Affiliate Login – IT Done Right”;
$pgDesc=”IT Done Right are an Laptop repair company based in Pitsea covering Basildon, Laindon and more…”;
$pgKeywords=”laptop repair Pitsea, laptop repair Basildon, laptop repairs Pitsea, laptop repairs Basildon”;
include ( ‘includes/header.php’ );
?>
<!–CONTENT–>
<div id=”column-whole”>
<h2 class=”title”>Affiliate Login</h2>
<hr class=”carved” />
<form action=”” method=”post” class=”signup”>
<h2>Name*:</h2> <input type=”text” name=”username” />
<br>
<h2>Password*:</h2> <input type=”password” name=”password” />
<br>
<input type=”submit” value=”Login” id=”submit” />
<a href=”reset-pass.php”>Forgot Password?</a> | <a href=”new-affiliate-signup.php”>Register</a>
</form>
<?php
include’config-db.php’;
if(!empty($_POST[‘username’]) && !empty($_POST[‘password’]))
{
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
//$id = $_GET[‘id’]; Can’t do this, because you don’t pass the ID through GET. You can’t really, as you don’t know the ID when the user logs in.
//check data
//Cant check the ID here either, as you don’t know it yet
$sql = “SELECT * FROM affiliates WHERE username=’$username’ AND password =’$password'”;
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()) {
$username = $row[“username”];
//Store the name in the session
$_SESSION[‘username’] = $username;
//You should be getting the ID HERE, as this is where you know who the User is.
$id = $row[‘id’];
header(“location:affiliate-profile.php?id=$id”);
exit();
}
}
else {
echo “<h2>Incorrect Username/Password</h2>”;
}
}
?>
</div>
<!–CONTENT–>
<?php include( ‘includes/footer.php’ ); ?>