Jump to content

struggling on .php?id=52


maxso

Recommended Posts

Ok, I have read many tutorials but non of these tutorials talk about

.php?id=52

or something along the lines of that.

 

When they register to my site they will get an ID on my database

 

Can anybody help me with how to get that ID to make there personal part

mysite.com/profile.php?id=56

 

I hope I made some sense

Link to comment
https://forums.phpfreaks.com/topic/138324-struggling-on-phpid52/
Share on other sites

It is actually quite simple to do this. I'm assuming your users table has an id field

 

$sql = 'SELECT id, username FROM users_table WHERE username='your_username'";
$result = mysql_query($result);

$row = mysql_fetch_assoc($result);

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

 

In profile.php to retrieve the id you'd use $_GET['id']

 

profile.php

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $user_id = (int) $_GET['id'];
    $sql = 'SELECT * FROM users_table WHERE id=$user_id";
    $result = mysql_query($result);

    $row = mysql_fetch_assoc($result);

    echo '<pre>'.print_r($row, true).'</pre>';
}

Im sorry but im realy confused.

 

I have a profile.php with what they need to do. When a person goes to the address bar and types .../profile.php?id=6 I need my secondary database which is called 'servers' to link to the table with the name of '6'.

 

Also it includes a text file named after the id.

 

I am sorry if I am confusing you aswell.

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.