Jump to content

[SOLVED] Link to Profile


Cetanu

Recommended Posts

I am using a login/registration script that gives people a profile, but  I cannot figure how to add links to the profiles automatically.

 

This is how I get a link for a user to go to THEIR OWN profile:

echo "<a href=\"profile.php?username=".$_SESSION['username']."\">View Profile</a>"; 

 

But what do I do if I want a link to be generated for each user, maybe next to their username on the memberlist? Or is that impossible-- do I need to manually make a link for every user?

Link to comment
https://forums.phpfreaks.com/topic/164712-solved-link-to-profile/
Share on other sites

What registration system are you using and can you show a link so people can understand more of what it is you want to do?

 

But to give you a basic idea

 

your line

 

echo "<a href=\"profile.php?username=".$_SESSION['username']."\">View Profile</a>";

 

where it says ".$_SESSION['username']."

 

you could replace with any valid user name in your database to see that users profile.

 

Hope that helps.

Yep, I could do that, but I would need to manually update a link every time a new user joins, right?

I guess I could use that while I am a small site. ;D

 

Here's the registration script:

<?php
//Create registration form (register.php)
include "db_connect.php";

if(!$_POST['submit'])
{

}
else
{
$first = protect($_POST['first']);
$username = protect($_POST['username']);
$password = protect($_POST['password']);
$pass_conf = protect($_POST['pass_conf']);
$email = protect($_POST['email']);
$about = protect($_POST['about']);
$errors = array();
$regex = "/^[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\.[a-z]{2,}$/i";
if(!preg_match($regex, $email))
{
  $errors[] = "E-mail is not in name@domain format!";
}

if(!$first || !$username || !$password || !$pass_conf || !$email || !$about)
{
   $errors[] = "You did not fill out the required fields";
}

$sql = "SELECT * FROM `users` WHERE `username`='{$username}'";
$query = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($query) > 0) 
{
  $errors[] = "Username already taken, please try another";
}
if(count($errors) > 0)
{
  echo "The following errors occured with your registration";
  echo "<font color=\"red\">";
  foreach($errors AS $error)
  {
    echo "<p>" . $error . "\n";
  }
  echo "</font>";
  echo "<a href=\"javascript:history.go(-1)\">Try again</a>";
  //we use javascript to go back rather than reloading the page 
  // so the user doesn't have to type in all that info again.
}
else
{
  $sql = "INSERT into `users`(`first`,`username`,`password`,`email`,`about`)
  VALUES ('$first','$username','".md5($password)."','$email','$about');";

$query = mysql_query($sql) or die(mysql_error());
echo "Thank You for registering {$first_name}! Your username is {$username}";
echo "<a href=\"index.php\"> Click here </a> to Login";
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.