Jump to content

URL-passed variables.. need some help ...


techiefreak05

Recommended Posts

i have, in my .htaccess file, i rewrite rule that rewrites something like this: www.mysite.com/myuser to www.profiles.mysite.com/index.php?user=myuser .. and since usernames arent used much in my site, only for the url, i use ID numbers.. so after they go to www.profiles.mysite.com/index.php?user=myuser . it grabs the ID # for the user "myuser" with this code:

[code]if(isset($_GET['username'])){

$conn = mysql_connect("************", "********", "******") or die(mysql_error());
mysql_select_db('****', $conn) or die(mysql_error());

$sql = "SELECT * FROM users WHERE username = '$_GET[username]' LIMIT 1";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
$id=$row[id];
$_GET['id']=$id;
$_GET['username']="";
}[/code]

and then ...index.php?username=myuser becomes ...index.php?id=1, then echos the information of the user with the given ID, with this code:

[code]if(isset($_GET['id'])){

$conn = mysql_connect("***", "***", "***") or die(mysql_error());
mysql_select_db('***', $conn) or die(mysql_error());

$sql = "SELECT * FROM zpageInfo,users WHERE id = '$_GET[id]' LIMIT 1";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
?>
<table>
<tr><td>
Username: <?php echo $row[username]; ?>
</td></tr>
<tr><td>
film: <?php echo $row[film]; ?>
</td></tr>
<tr><td>
music: <?php echo $row[music]; ?>
</td></tr>
<tr><td>
about me: <?php echo $row[aboutme]; ?>
</td></tr>
<tr><td>
friends: <?php echo $row[friends]; ?>
</td></tr>
literature: <?php echo $row[literature]; ?>
</td></tr>
<tr><td>
location: <?php echo $row[location]; ?>
</td></tr>
</table>
<?
}
?>[/code]


thats confusing.. would there be an easier way to, if  "username" is set in the url, to get the ID of that username, and change the username to nothing and set the ID?

i tried to explain it the easiest i could...
Link to comment
https://forums.phpfreaks.com/topic/26140-url-passed-variables-need-some-help/
Share on other sites

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.