Jump to content

how to make pages like blah?user=username


rallokkcaz

Recommended Posts

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.


Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

[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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.