Jump to content


Photo

how to show userinfo!


  • Please log in to reply
10 replies to this topic

#1 rallokkcaz

rallokkcaz
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts
  • LocationSomewhere, CA (Cactus Area)

Posted 02 September 2006 - 10:17 PM

pleeze help i wanna show the users info on a page

pleeze help!

thank you

#2 contrabandheart

contrabandheart
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 September 2006 - 10:20 PM

Do you store your user information in MySQL?

If you want help, you should include more information about what it is you actually want to do, how the information you wish to access is stored, etc. Vague requests like "please tell me how to show a user's information" doesn't give anyone who wishes to help you any sort of starting point at all.

-Cass
You are the weakest Uniform Resource Locator... Goodbye.

#3 rallokkcaz

rallokkcaz
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts
  • LocationSomewhere, CA (Cactus Area)

Posted 02 September 2006 - 10:23 PM

yes i do

here's a link to the page
http://www.pokebash.com/user.php
www.pokebash.com/profiles.php

here's the code for profiles.php

<?php


if($_GET['userid'])
{
$id = $_GET['userid'];
$get['userdata'] = mysql_query("SELECT * FROM pokebash_users WHERE userid='$id'");

$get['userdata'] = mysql_fetch_array($get['userdata']);

echo 'Username: ' .$get['userdata']['username'] .'
';
echo 'E-mail: ' .$get['userdata']['email'] .'
';
echo 'fullname: ' .$get['userdata']['fullname'];

}
else
{
//########REDIRECTS TO YOUR HOME PAGE IF UID IS NOT PRESENT IN THE URL#########
echo '<meta http-equiv="refresh" content="0;URL=user.php" />';
}
?>

the problem is that nothing shows up on the page
and it redirects me to the userlist

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 10:30 PM

it is becuase your are passing a id (profile.php?id=1) parameter and not a userid parameter, which is what your script is using, you want to use $_GET['id'] and not $_GET['userid'])

So change this:
if($_GET['userid'])
{
$id = $_GET['userid'];
To this:
if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id = $_GET['id'];


#5 rallokkcaz

rallokkcaz
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts
  • LocationSomewhere, CA (Cactus Area)

Posted 02 September 2006 - 10:34 PM

now it says there is an error!

here's the error

Parse error: syntax error, unexpected T_BOOLEAN_AND in /home/pokebash/public_html/profiles.php on line 3

what should i do to stop that?


#6 contrabandheart

contrabandheart
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 September 2006 - 10:39 PM

Okay...

We'll do this the easy way.

Or the hard way, however you want to see it.

What are the names of the rows within your table?

Give them to me in order, and I'll write a new query that should word. (Emphasis on SHOULD).
You are the weakest Uniform Resource Locator... Goodbye.

#7 rallokkcaz

rallokkcaz
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts
  • LocationSomewhere, CA (Cactus Area)

Posted 02 September 2006 - 10:51 PM

ok i fixed one prob i had

i don't need a new query
i just want to display the user info

#8 rallokkcaz

rallokkcaz
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts
  • LocationSomewhere, CA (Cactus Area)

Posted 02 September 2006 - 10:55 PM

ok wildteen
what does ['userdata'] do?

cause i don't know what to do with it

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 11:03 PM

Well you've setup an array ($get) with a key called userdata. its part of the get array you setup

#10 rallokkcaz

rallokkcaz
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts
  • LocationSomewhere, CA (Cactus Area)

Posted 02 September 2006 - 11:20 PM

thank you!
now is there a way to let the user edit there info?

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 11:39 PM

Create a form which submits to itself, then use PHP to populate the form fields. Have a submit button and  name it update. Then have an if statement which checks whether the submit button been pressed. If has update the database.

Heres an example:
<?php

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id = $_GET['id'];

    $sql = "SELECT * FROM pokebash_users WHERE userid='$id'";

    $result = @mysql_query($sql) or die(mysql_error());

    $user = mysql_fetch_assoc($result);

    echo <<<HTMLFORM
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table border="1" cellpadding="2" cellspacing="1" width="400">
  <tr>
    <td wdith="35%">Username:</td>
    <td>{$user['username']}</td>
  </tr>
  <tr>
    <td>Full Name:</td>
    <td><input type="text" name="fullname" value="{$user['fullname']}" /></td>
  </tr>
  <tr>
    <td>Email Address:</td>
    <td><input type="text" name="email" value="{$user['email']}" /></td>
  </tr>
  <tr>
    <td colspan="2">
      <input type="hidden" name="userid" value="{$user['userid']}" />
      <input type="submit" name="update" value="Update Profile">
    </td>
  </tr>
</table>
</form>
HTMLFORM;
}
elseif(isset($_POST['update']))
{
    foreach($_POST as $field_name => $field_value)
    {
        ${$field_name} = mysql_real_escape_string($field_value);
    }

    $sql = "UPDATE pokebash_users email='$email', fullname='$fullname' WHERE userid='$userid'";

    $result = mysql_query($sql) or die(mysql_error());

    echo "Successfully updated profile";
}
else
{
    //########REDIRECTS TO YOUR HOME PAGE IF UID IS NOT PRESENT IN THE URL#########
    echo '<meta http-equiv="refresh" content="0;URL=user.php" />';
}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users