Jump to content

how to make pages like blah?user=username


rallokkcaz

Recommended Posts

in the future, please try to search the forums for your question, before making a new post. here is a thread that addresses this very question, still on the very first page of the forum.

http://www.phpfreaks.com/forums/index.php/topic,106521.0.html

my first guess is that your username field in your table is varchar(10) and that's why you only have 10 chars for your usernames.

as far as taking you to the login page and not the user info... you have the links pointing to users.php. is that code up there in users.php or is that in another file? because the code that displays the info is in that same code up there ^ so if you are pointing the links to somewhere else...

and actually, you don't seem to have anything even in that code above, to display the info, after it's retrieved.  so where's the part of your code where you're trying to display it?

as far as getting the login page after you click on the link: my first guess is that you have your script checking to see if the person is logged in or not, but you aren't carrying that info over to the next page.  Or rather, maybe you are trying to directly access this script for testing purposes, and you don't have any session_start() or you aren't "logged in", your "if not logged in" script is kicking you back to the login page.  but these are only guesses, as i don't have access to the rest of your code.


ok i fixed the user character thing!!!

and i was linking to the wrong page oops

but how can i make it si when you click the links
it goes to the users info?

here's the page/code!

[url=http://www.pokebash.com/user.php]http://www.pokebash.com/user.php[/url]
[code]<? include ("header.php"); ?>

<?php
  //connect to and select db
  $conn = mysql_connect('localhost','','') or die(mysql_error());
  $db = mysql_select_db('pokebash_users',$conn) or die(mysql_error());
 
  //get a list of the info from the table to make the linkies
  $sql = "select * from maaking_users";
  $result = mysql_query($sql, $conn) or die(mysql_error());

  // for each row fetched from the results... 
  while ($list = mysql_fetch_array($result)) {
      //make the custom linkie
      echo "<a href= 'http://www.pokebash.com/user.php?id={$list['username']}'>{$list['username']}</a><br>";
  } // end while

  // if the user clicked on a linkie and therefore an id exists (the is_numeric is a basic security precaution) ...
  if (is_numeric($_GET['username'])) {
      // for easier var syntax handling
      $id = $_GET['username'];
     
      // select the video from the db based on its id     
      $sql = "select username from maaking_users where video_id = '$id'";
      $result = mysql_query($sql, $conn) or die(mysql_error());

      // if a video was found...
      $videofound = mysql_num_rows($result);
      if ($videofound) {
        $user = mysql_fetch_array($result);
        include ("header.php");
echo "<center> $id";

      } // end if found
  } // end if there was a linkie clicked
[/code]
Umm so what exactly are you trying to accomplish?  Like where you can go to page.php?user=<user> and it displays theyre user info?  It would help if you clarified what youre trying to do...

(PS In response to your sig... I started PHP when I was about 12.5 :D)
[quote author=corbin link=topic=106583.msg426390#msg426390 date=1157173164]
Umm so what exactly are you trying to accomplish?  Like where you can go to page.php?user=<user> and it displays theyre user info?  It would help if you clarified what youre trying to do...
[/quote]
yes that is what i want to do!
can you pleeze help?
If you're trying to see user's info you'll normall have a page like this  user.php?uid=1

And then...you can get the info with something like this

<?php
//###########################################################
if($_GET['uid'])
  {
  $sql['userdata'] = mysql_query("SELECT * FROM users WHERE userid='".$_GET['uid']."' ");
    //########IF USERID EXISTS#####
    if(mysql_num_rows($sql['userdata'])>0)
      {
      $sql['userdata'] = mysql_fetch_array($sql['userdata']);
        //######GET & DISPLAY SOME USER DATA#####
        $username = $sql['userdata']['username'];
        $email = $sql['userdata']['email'];
        echo $username .'<br />'. $email;

      }
    //#####USER DOESN'T EXIST######
  else
    {
    echo 'This user is not in our database';
    }

  }
//#########REDIRECT IF UID IS NOT IN THE URL#########
else
{
  echo '<meta http-equiv="refresh" content="0;URL=any_url_you_choose" />';
}
?>

That's what I'd do to fetch user data hope it helps you
ok i need help with this
????????????????????

:(

i can't get it to work

when i link the to the user profile
the page shows blank?
some one help
here's the page [url=http://www.pokebash.com/user.php]http://www.pokebash.com/user.php[/url]
and the code
[code]<?php
include ("config.php");
//###########################################################
if($_GET['uid'])
  {
  $sql['userdata'] = mysql_query("SELECT * FROM pokebash_users WHERE maaking_users='".$_GET['uid']."' ");
    //########IF USERID EXISTS#####
    if(mysql_num_rows($sql['userdata'])>0)
      {
      $sql['userdata'] = mysql_fetch_array($sql['userdata']);
        //######GET & DISPLAY SOME USER DATA#####
        $username = $sql['userdata']['username'];
        $email = $sql['userdata']['email'];
        echo $username .'
'. $email;

      }
    //#####USER DOESN'T EXIST######
  else
    {
    echo 'This user is not in our database';
    }

  }
//#########REDIRECT IF UID IS NOT IN THE URL#########
else
{
  echo '<meta http-equiv="refresh" content="0;URL=user.php" />';
}
?>[/code]

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.