arning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

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

";

$row=mysql_fetch_array($sql);
echo “


";

echo "

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.

Username:
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!

So I got it working now without the error message, but when I go to edit information and update it, I get the alert that it’s been updated but the login and password don’t change?

As a side note the codes are updated so there is proper spacing in the $row column, and the form input (username) matches with the isset function (username) instead of ‘registered’.

What is this command?

echo “”;

In script this look like:

(normal)

So, maybe you see it… No ending on your location code… Should be:
window.location=‘myprofile.php’;

Hope that is all it is for you… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service