Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/19520-how-to-show-userinfo/#findComment-84867
Share on other sites

yes i do

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

here's the code for profiles.php

[code]<?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" />';
}
?>[/code]

the problem is that nothing shows up on the page
and it redirects me to the userlist
Link to comment
https://forums.phpfreaks.com/topic/19520-how-to-show-userinfo/#findComment-84868
Share on other sites

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:
[code]
if($_GET['userid'])
{
$id = $_GET['userid'];[/code]
To this:
[code]
if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id = $_GET['id'];[/code]
Link to comment
https://forums.phpfreaks.com/topic/19520-how-to-show-userinfo/#findComment-84870
Share on other sites

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:
[code]<?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" />';
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/19520-how-to-show-userinfo/#findComment-84901
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.