Trying to create a simple profile page for the user after they login, where they can edit their display name (‘registered’, not username) and their password.
[php]session_start();
include(‘config.php’);
$sql = mysql_query( “SELECT * FROM users WHERE id=’”.$_SESSION[‘id’]."’" );
echo "
Profile
Name: | “.$row[‘registered’].” |
---|---|
Password: | <input type=‘password’ value=’”.$row[‘password’]."’ disabled=‘true’ /> |
"; [/php]
editprofile.php
[php]include(‘config.php’);
if(isset($_POST[‘btnedit’])){
$registered = $_POST[‘registered’];
$password = $_POST[‘password’];
$sql = mysql_query( “UPDATE users SET registered=’”.$registered."’, password=’".$password."’ WHERE id=’".$_SESSION[‘id’]."’" );
if($sql){
echo “”;
}else{
echo “”;
}
}
$sql = mysql_query( “SELECT * FROM users WHERE id=’”.$_SESSION[‘id’]."’" );
$row = mysql_fetch_array($sql);
echo "
Edit profile
registered: | |
---|---|
password: |
"; [/php]
login.php (so you can see variables I use)
[php]session_start();
include(‘config.php’);
if($loggedin == ‘0’)
{
if(isset($_POST[‘submit’]))
{
// Make sure all forms were filled out.
if((!isset($_POST[‘username’])) || (!isset($_POST[‘pass’]))
|| ($_POST[‘username’] == ‘’) || ($_POST[‘pass’] == ‘’))
die(“Please fill out the form completely.
Continue”);
// Get user’s record from database
$player = @mysql_query(“SELECT id, username, password, registered, lastlogin FROM users WHERE username = '”.$_POST[‘username’]."’");
$player = @mysql_fetch_assoc($player);
mysql_real_escape_string($username);
mysql_real_escape_string($password);
if($player[‘id’] == false)
die(“Sorry, that user is not in our database.
Back”);
else if($player[‘password’] != md5($_POST[‘pass’]))
die(“Wrong password!
Back”);
$_SESSION[‘id’] = $player[‘id’];
$_SESSION[‘username’] = $player[‘username’];
$_SESSION[‘password’] = $player[‘password’];
$date = date(“m/d/y”);
$update = @mysql_query(“UPDATE users SET lastlogin = ‘$date’ WHERE id = '”.$_SESSION[‘id’]."’");
echo ‘You are now logged in!’;
}
else
{
echo 'You are not logged in.
Password:
Would you like to register?'; } } else { echo 'You are logged in! Welcome to my game, '.$_SESSION['username'].'!
Click Here to Logout';
}
[/php]
I get the error message warnin: mysql_fetch_array() (in myprofile.php) expects parameter 1 to be resource, boolean given. What did I do wrong with the array here? Thanks for any insight!