Jump to content

mysql_fetch_array() expects parameter 1 to be resource error =P


Recommended Posts

Hey guys, i was recently making a new PHP code and when i tested it out it gave me this error:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\tools\edit_infos.php on line 167

 

I don't know what the problem is.

Here is 'Line 167':

//Line 167			
$dnn = mysql_fetch_array(mysql_query('select username,password,email,desc,keys,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username="'.$_SESSION['username'].'"'));
		$username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8');
		$password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8');
		$email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8');
		$desc = htmlentities($dnn['desc'], ENT_QUOTES, 'UTF-8');
		$keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8');
		$logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8');
		$webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8');
		$forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8');
		$hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8');
		$chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8');
		$staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8');
		$newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8');
		$newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8');
		$news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8');
		$op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8');
		$opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8');
		$oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8');

 

And here is the whole page code if needed.

 

<?php
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
        <title>Edit my personnal informations</title>
    </head>
    <body>
    	<div class="header">
        	<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a>
    </div>
<?php
//We check if the user is logged
if(isset($_SESSION['username']))
{
//We check if the form has been sent
if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['desc'], $_POST['keys'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3'], $_POST['desc']))
{
	//We remove slashes depending on the configuration
	if(get_magic_quotes_gpc())
	{
		$_POST['username'] = stripslashes($_POST['username']);
		$_POST['password'] = stripslashes($_POST['password']);
		$_POST['passverif'] = stripslashes($_POST['passverif']);
		$_POST['email'] = stripslashes($_POST['email']);
		$_POST['desc'] = stripslashes($_POST['desc']);
		$_POST['keys'] = stripslashes($_POST['keys']);
		$_POST['logo'] = stripslashes($_POST['logo']);
		$_POST['webclient'] = stripslashes($_POST['webclient']);
		$_POST['forums'] = stripslashes($_POST['forums']);
		$_POST['hiscores'] = stripslashes($_POST['hiscores']);
		$_POST['donate'] = stripslashes($_POST['logo']);
		$_POST['chatbox'] = stripslashes($_POST['chatbox']);
		$_POST['staff'] = stripslashes($_POST['staff']);
		$_POST['newstitle'] = stripslashes($_POST['newstitle']);
		$_POST['newsimage'] = stripslashes($_POST['newsimage']);
		$_POST['news'] = stripslashes($_POST['news']);
		$_POST['op1'] = stripslashes($_POST['op1']);
		$_POST['op2'] = stripslashes($_POST['op2']);
		$_POST['op3'] = stripslashes($_POST['op3']);
	}
	//We check if the two passwords are identical
	if($_POST['password']==$_POST['passverif'])
	{
		//We check if the password has 6 or more characters
		if(strlen($_POST['password'])>=6)
		{
			//We check if the email form is valid
			if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))
			{
				//We protect the variables
				$username = mysql_real_escape_string($_POST['username']);
				$password = mysql_real_escape_string($_POST['password']);
				$email = mysql_real_escape_string($_POST['email']);
				$desc = mysql_real_escape_string($_POST['desc']);
				$keys = mysql_real_escape_string($_POST['keys']);
				$logo = mysql_real_escape_string($_POST['logo']);
				$webclient = mysql_real_escape_string($_POST['webclient']);
				$forums = mysql_real_escape_string($_POST['forums']);
				$hiscores = mysql_real_escape_string($_POST['hiscores']);
				$donate = mysql_real_escape_string($_POST['donate']);
				$chatbox = mysql_real_escape_string($_POST['chatbox']);
				$staff = mysql_real_escape_string($_POST['staff']);
				$newstitle = mysql_real_escape_string($_POST['newstitle']);
				$newsimage = mysql_real_escape_string($_POST['newsimage']);
				$news = mysql_real_escape_string($_POST['news']);
				$op = mysql_real_escape_string($_POST['op1']);
				$opp = mysql_real_escape_string($_POST['op2']);
				$oppp = mysql_real_escape_string($_POST['op3']);
				//We check if there is no other user using the same username
				$dn = mysql_fetch_array(mysql_query('select count(*) as nb from users where username="'.$username.'"'));
				//We check if the username changed and if it is available
				if($dn['nb']==0 or $_POST['username']==$_SESSION['username'])
				{
					//We edit the user informations
					if(mysql_query('update users set username="'.$username.'", password="'.$password.'", email="'.$email.'", desc="'.$desc.'", keys="'.$keys.'", logo="'.$logo.'", webclient="'.$webclient.'", forums="'.$forums.'", hiscores="'.$hiscores.'", chatbox="'.$chatbox.'", staff="'.$staff.'", newstitle="'.$newstitle.'", newsimage="'.$newsimage.'", news="'.$news.'", op1="'.$op1.'", op2="'.$op2.'", op3="'.$op3.'" where id="'.mysql_real_escape_string($_SESSION['userid']).'"'))
					{
						//We dont display the form
						$form = false;
						//We delete the old sessions so the user need to log again
						unset($_SESSION['username'], $_SESSION['userid']);
?>
<div class="message">Your informations have successfuly been updated. You need to log again.<br />
<a href="connexion.php">Log in</a></div>
<?php
					}
					else
					{
						//Otherwise, we say that an error occured
						$form = true;
						$message = 'An error occurred while updating your informations.';
					}
				}
				else
				{
					//Otherwise, we say the username is not available
					$form = true;
					$message = 'The username you want to use is not available, please choose another one.';
				}
			}
			else
			{
				//Otherwise, we say the email is not valid
				$form = true;
				$message = 'The email you entered is not valid.';
			}
		}
		else
		{
			//Otherwise, we say the password is too short
			$form = true;
			$message = 'Your password must contain at least 6 characters.';
		}
	}
	else
	{
		//Otherwise, we say the passwords are not identical
		$form = true;
		$message = 'The passwords you entered are not identical.';
	}
}
else
{
	$form = true;
}
if($form)
{
	//We display a message if necessary
	if(isset($message))
	{
		echo '<strong>'.$message.'</strong>';
	}
	//If the form has already been sent, we display the same values
	if(isset($_POST['username'],$_POST['password'],$_POST['desc'], $_POST['keys'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3']))
	{
		$pseudo = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
		if($_POST['password']==$_POST['passverif'])
		{
			$password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8');
		}
		else
		{
			$password = '';
		}
		$email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
		$desc = htmlentities($_POST['desc'], ENT_QUOTES, 'UTF-8');
		$keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8');
		$logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8');
		$webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8');
		$forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8');
		$hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8');
		$chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8');
		$staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8');
		$newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8');
		$newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8');
		$news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8');
		$op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8');
		$opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8');
		$oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8');
	}
	else
	{
		//otherwise, we display the values of the database
		$dnn = mysql_fetch_array(mysql_query('select username,password,email,desc,keys,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username="'.$_SESSION['username'].'"'));
		$username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8');
		$password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8');
		$email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8');
		$desc = htmlentities($dnn['desc'], ENT_QUOTES, 'UTF-8');
		$keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8');
		$logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8');
		$webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8');
		$forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8');
		$hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8');
		$chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8');
		$staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8');
		$newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8');
		$newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8');
		$news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8');
		$op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8');
		$opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8');
		$oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8');
	}
	//We display the form
?>
<div class="content">
    <form action="edit_infos.php" method="post">
        You can edit your informations:<br />
        <div class="center">
            <label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo $username; ?>" /><br />
            <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" id="password" value="<?php echo $password; ?>" /><br />
            <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" id="passverif" value="<?php echo $password; ?>" /><br />
            <label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br />
            <label for="desc">Webclient/Server Description</label><textarea name="desc" id="desc" rows="3" value="<?php echo $desc; ?>"></textarea><br />
            <label for="keys">Webclient/Server Tags<span class="small">(Seperate with comma's)</span></label><input type="text" name="keys" id="keys" value="<?php echo $keys; ?>" /><br />
            <label for="logo">Website/Server Logo Link</label><input type="text" name="logo" id="logo" value="<?php echo $logo; ?>" /><br />
            <label for="webclient">Webclient Link</label><input type="text" name="webclient" id="webclient" value="<?php echo $webclient; ?>" /><br />
            <label for="forums">Forums Link</label><input type="text" name="forums" id="forums" value="<?php echo $forums; ?>" /><br />
            <label for="hiscores">Hiscores Link</label><input type="text" name="hiscores" id="hiscores" value="<?php echo $hiscores; ?>" /><br />
            <label for="chatbox">Chatbox Html</label><textarea name="chatbox" rows="3" id="chatbox" value="<?php echo $chatbox; ?>" ></textarea><br />
            <label for="staff">Staff Page Link</label><input type="text" name="staff" id="staff" value="<?php echo $staff; ?>" /><br />
            <label for="newstitle">News Article Title</label><input type="text" name="newstitle" id="newstitle" value="<?php echo $newstitle; ?>" /><br />
            <label for="newsimage">News Article Image Link<span class="small">(Displayed under title)</span></label><input type="text" name="newsimage" id="newsimage" value="<?php echo $newsimage; ?>" /><br />
            <label for="news">News Article</label><textarea name="news" rows="3" id="news" value="<?php echo $news; ?>" ></textarea><br />
<label for="op1">Optional Link #1</label><input type="text" name="op" id="op" value="<?php echo $op; ?>" /><br />
<label for="op2">Optional Link #2</label><input type="text" name="opp" id="opp" value="<?php echo $opp; ?>" /><br />
<label for="op3">Optional Link #3</label><input type="text" name="oppp" id="oppp" value="<?php echo $oppp; ?>" /><br />
            <input type="submit" value="Send" />
        </div>
    </form>
</div>
<?php
}
}
else
{
?>
<div class="message">To access this page, you must be logged.<br />
<a href="connexion.php">Log in</a></div>
<?php
}
?>
	<div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div>
</body>
</html>

Anyway, i hope someone can help me solve this.

Thanks

That error means you have a syntax error in your query. Write that single line as multiple lines so you can find out what the error is:

<?php
$q = "select username,password,email,desc,keys,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username='{$_SESSION['username']}'";
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
$dnn = mysql_fetch_assoc($rs);
?>

 

Ken

AFTER you have changed you're code to reflect what Ken posted take note of the

...or die ("Problem with the query: $q<br>" . mysql_error());

This should be used during development to handle any errors your queries generate.  Also, you shouldn't use double quotes to wrap string values in SQL, always use single ones.

 

Now you can put the spaces in after the comma's and the = and as long as your field names and table name are accurate you should be good to go.  If not you should at least get a much more practical error message.

Okay i get no more errors and i fixed the 'desc' and 'keys', but now it won't update the users info.

Here is the updated code:

<?php
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
        <title>Edit my personnal informations</title>
    </head>
    <body>
    	<div class="header">
        	<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a>
    </div>
<?php
//We check if the user is logged
if(isset($_SESSION['username']))
{
//We check if the form has been sent
if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['description'], $_POST['keywords'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3'], $_POST['description']))
{
	//We remove slashes depending on the configuration
	if(get_magic_quotes_gpc())
	{
		$_POST['username'] = stripslashes($_POST['username']);
		$_POST['password'] = stripslashes($_POST['password']);
		$_POST['passverif'] = stripslashes($_POST['passverif']);
		$_POST['email'] = stripslashes($_POST['email']);
		$_POST['description'] = stripslashes($_POST['description']);
		$_POST['keywords'] = stripslashes($_POST['keywords']);
		$_POST['logo'] = stripslashes($_POST['logo']);
		$_POST['webclient'] = stripslashes($_POST['webclient']);
		$_POST['forums'] = stripslashes($_POST['forums']);
		$_POST['hiscores'] = stripslashes($_POST['hiscores']);
		$_POST['donate'] = stripslashes($_POST['logo']);
		$_POST['chatbox'] = stripslashes($_POST['chatbox']);
		$_POST['staff'] = stripslashes($_POST['staff']);
		$_POST['newstitle'] = stripslashes($_POST['newstitle']);
		$_POST['newsimage'] = stripslashes($_POST['newsimage']);
		$_POST['news'] = stripslashes($_POST['news']);
		$_POST['op1'] = stripslashes($_POST['op1']);
		$_POST['op2'] = stripslashes($_POST['op2']);
		$_POST['op3'] = stripslashes($_POST['op3']);
	}
	//We check if the two passwords are identical
	if($_POST['password']==$_POST['passverif'])
	{
		//We check if the password has 6 or more characters
		if(strlen($_POST['password'])>=6)
		{
			//We check if the email form is valid
			if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))
			{
				//We protect the variables
				$username = mysql_real_escape_string($_POST['username']);
				$password = mysql_real_escape_string($_POST['password']);
				$email = mysql_real_escape_string($_POST['email']);
				$description = mysql_real_escape_string($_POST['description']);
				$keywords = mysql_real_escape_string($_POST['keywords']);
				$logo = mysql_real_escape_string($_POST['logo']);
				$webclient = mysql_real_escape_string($_POST['webclient']);
				$forums = mysql_real_escape_string($_POST['forums']);
				$hiscores = mysql_real_escape_string($_POST['hiscores']);
				$donate = mysql_real_escape_string($_POST['donate']);
				$chatbox = mysql_real_escape_string($_POST['chatbox']);
				$staff = mysql_real_escape_string($_POST['staff']);
				$newstitle = mysql_real_escape_string($_POST['newstitle']);
				$newsimage = mysql_real_escape_string($_POST['newsimage']);
				$news = mysql_real_escape_string($_POST['news']);
				$op = mysql_real_escape_string($_POST['op1']);
				$opp = mysql_real_escape_string($_POST['op2']);
				$oppp = mysql_real_escape_string($_POST['op3']);
				//We check if there is no other user using the same username
				$dn = mysql_fetch_array(mysql_query('select count(*) as nb from users where username="'.$username.'"'));
				//We check if the username changed and if it is available
				if($dn['nb']==0 or $_POST['username']==$_SESSION['username'])
				{
					//We edit the user informations
					if(mysql_query('update users set username="'.$username.'", password="'.$password.'", email="'.$email.'", description="'.$description.'", keywords="'.$keywords.'", logo="'.$logo.'", webclient="'.$webclient.'", forums="'.$forums.'", hiscores="'.$hiscores.'", chatbox="'.$chatbox.'", staff="'.$staff.'", newstitle="'.$newstitle.'", newsimage="'.$newsimage.'", news="'.$news.'", op1="'.$op1.'", op2="'.$op2.'", op3="'.$op3.'" where id="'.mysql_real_escape_string($_SESSION['userid']).'"'))
					{
						//We dont display the form
						$form = false;
						//We delete the old sessions so the user need to log again
						unset($_SESSION['username'], $_SESSION['userid']);
?>
<div class="message">Your informations have successfuly been updated. You need to log again.<br />
<a href="connexion.php">Log in</a></div>
<?php
					}
					else
					{
						//Otherwise, we say that an error occured
						$form = true;
						$message = 'An error occurred while updating your informations.';
					}
				}
				else
				{
					//Otherwise, we say the username is not available
					$form = true;
					$message = 'The username you want to use is not available, please choose another one.';
				}
			}
			else
			{
				//Otherwise, we say the email is not valid
				$form = true;
				$message = 'The email you entered is not valid.';
			}
		}
		else
		{
			//Otherwise, we say the password is too short
			$form = true;
			$message = 'Your password must contain at least 6 characters.';
		}
	}
	else
	{
		//Otherwise, we say the passwords are not identical
		$form = true;
		$message = 'The passwords you entered are not identical.';
	}
}
else
{
	$form = true;
}
if($form)
{
	//We display a message if necessary
	if(isset($message))
	{
		echo '<strong>'.$message.'</strong>';
	}
	//If the form has already been sent, we display the same values
	if(isset($_POST['username'],$_POST['password'],$_POST['description'], $_POST['keywords'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3']))
	{
		$pseudo = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
		if($_POST['password']==$_POST['passverif'])
		{
			$password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8');
		}
		else
		{
			$password = '';
		}
		$email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
		$description = htmlentities($_POST['description'], ENT_QUOTES, 'UTF-8');
		$keywords = htmlentities($dnn['keywords'], ENT_QUOTES, 'UTF-8');
		$logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8');
		$webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8');
		$forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8');
		$hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8');
		$chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8');
		$staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8');
		$newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8');
		$newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8');
		$news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8');
		$op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8');
		$opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8');
		$oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8');
	}
	else
	{
		//otherwise, we display the values of the database
		$q = "select username,password,email,description,keywords,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username='{$_SESSION['username']}'";
		$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
		$dnn = mysql_fetch_assoc($rs);
		$username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8');
		$password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8');
		$email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8');
		$description = htmlentities($dnn['description'], ENT_QUOTES, 'UTF-8');
		$keywords = htmlentities($dnn['keywords'], ENT_QUOTES, 'UTF-8');
		$logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8');
		$webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8');
		$forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8');
		$hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8');
		$chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8');
		$staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8');
		$newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8');
		$newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8');
		$news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8');
		$op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8');
		$opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8');
		$oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8');
	}
	//We display the form
?>
<div class="content">
    <form action="edit_infos.php" method="post">
        You can edit your informations:<br />
        <div class="center">
            <label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo $username; ?>" /><br />
            <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" id="password" value="<?php echo $password; ?>" /><br />
            <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" id="passverif" value="<?php echo $password; ?>" /><br />
            <label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br />
            <label for="description">Webclient/Server Description</label><textarea name="description" id="description" rows="3" value="<?php echo $description; ?>"></textarea><br />
            <label for="keywords">Webclient/Server Tags<span class="small">(Seperate with comma's)</span></label><input type="text" name="keywords" id="keywords" value="<?php echo $keywords; ?>" /><br />
            <label for="logo">Website/Server Logo Link</label><input type="text" name="logo" id="logo" value="<?php echo $logo; ?>" /><br />
            <label for="webclient">Webclient Link</label><input type="text" name="webclient" id="webclient" value="<?php echo $webclient; ?>" /><br />
            <label for="forums">Forums Link</label><input type="text" name="forums" id="forums" value="<?php echo $forums; ?>" /><br />
            <label for="hiscores">Hiscores Link</label><input type="text" name="hiscores" id="hiscores" value="<?php echo $hiscores; ?>" /><br />
            <label for="chatbox">Chatbox Html</label><textarea name="chatbox" rows="3" id="chatbox" value="<?php echo $chatbox; ?>" ></textarea><br />
            <label for="staff">Staff Page Link</label><input type="text" name="staff" id="staff" value="<?php echo $staff; ?>" /><br />
            <label for="newstitle">News Article Title</label><input type="text" name="newstitle" id="newstitle" value="<?php echo $newstitle; ?>" /><br />
            <label for="newsimage">News Article Image Link<span class="small">(Displayed under title)</span></label><input type="text" name="newsimage" id="newsimage" value="<?php echo $newsimage; ?>" /><br />
            <label for="news">News Article</label><textarea name="news" rows="3" id="news" value="<?php echo $news; ?>" ></textarea><br />
<label for="op1">Optional Link #1</label><input type="text" name="op" id="op" value="<?php echo $op; ?>" /><br />
<label for="op2">Optional Link #2</label><input type="text" name="opp" id="opp" value="<?php echo $opp; ?>" /><br />
<label for="op3">Optional Link #3</label><input type="text" name="oppp" id="oppp" value="<?php echo $oppp; ?>" /><br />
            <input type="submit" value="Send" />
     </div>
    </form>
</div>
<?php
}
}
else
{
?>
<div class="message">To access this page, you must be logged.<br />
<a href="connexion.php">Log in</a></div>
<?php
}
?>
	<div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div>
</body>
</html>

right, swap in the following code section for what is there already.

						//We edit the user informations
					$update_q = "UPDATE users SET username = '$username', password = '$password', email = '$email', description = '$description' " .
					"keywords = '$keywords', logo = '$logo', webclient = '$webclient', forums = '$forums', hiscores = '$hiscores', chatbox = '$chatbox', " .
					"staff = '$staff', newstitle = '$newstitle', newsimage = '$newsimage', news = '$news', op1 = '$op1', op2 = '$op2', op3 = '$op3' " .
					"WHERE id = ".mysql_real_escape_string($_SESSION['userid']);
                                                $update_action = mysql_query($update_q) or die ('ERROR! Unable to perform update<br>'.mysql_error().'<br><br>This error occured while atempting to run the following code:<br>'.$update_q);
					if (mysql_affected_rows() > 0) {
						//We dont display the form
						$form = false;
						//We delete the old sessions so the user need to log again
						unset($_SESSION['username'], $_SESSION['userid']);
?>

 

I have made the assumption that the id field in your WHERE clause is numerical, as such I have removed the quotes from arround the variable.  if there are any other fields that are of type Integer you should remove the quotes from the associated variables there too.

 

Let me know how you get on.

Ye idk man. It still doesn't update. I feel like giving up :C. Idk why its not working.

Can you take a look at the whole code?

Here is the whole code:

<?php
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
        <title>Edit my personnal informations</title>
    </head>
    <body>
    	<div class="header">
        	<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a>
    </div>
<?php
//We check if the user is logged
if(isset($_SESSION['username']))
{
//We check if the form has been sent
if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['description'], $_POST['keywords'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3']))
{
	//We remove slashes depending on the configuration
	if(get_magic_quotes_gpc())
	{
		$_POST['username'] = stripslashes($_POST['username']);
		$_POST['password'] = stripslashes($_POST['password']);
		$_POST['passverif'] = stripslashes($_POST['passverif']);
		$_POST['email'] = stripslashes($_POST['email']);
		$_POST['description'] = stripslashes($_POST['description']);
		$_POST['keywords'] = stripslashes($_POST['keywords']);
		$_POST['logo'] = stripslashes($_POST['logo']);
		$_POST['webclient'] = stripslashes($_POST['webclient']);
		$_POST['forums'] = stripslashes($_POST['forums']);
		$_POST['hiscores'] = stripslashes($_POST['hiscores']);
		$_POST['donate'] = stripslashes($_POST['logo']);
		$_POST['chatbox'] = stripslashes($_POST['chatbox']);
		$_POST['staff'] = stripslashes($_POST['staff']);
		$_POST['newstitle'] = stripslashes($_POST['newstitle']);
		$_POST['newsimage'] = stripslashes($_POST['newsimage']);
		$_POST['news'] = stripslashes($_POST['news']);
		$_POST['op1'] = stripslashes($_POST['op1']);
		$_POST['op2'] = stripslashes($_POST['op2']);
		$_POST['op3'] = stripslashes($_POST['op3']);
	}
	//We check if the two passwords are identical
	if($_POST['password']==$_POST['passverif'])
	{
		//We check if the password has 6 or more characters
		if(strlen($_POST['password'])>=6)
		{
			//We check if the email form is valid
			if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))
			{
				//We protect the variables
				$username = mysql_real_escape_string($_POST['username']);
				$password = mysql_real_escape_string($_POST['password']);
				$email = mysql_real_escape_string($_POST['email']);
				$description = mysql_real_escape_string($_POST['description']);
				$keywords = mysql_real_escape_string($_POST['keywords']);
				$logo = mysql_real_escape_string($_POST['logo']);
				$webclient = mysql_real_escape_string($_POST['webclient']);
				$forums = mysql_real_escape_string($_POST['forums']);
				$hiscores = mysql_real_escape_string($_POST['hiscores']);
				$donate = mysql_real_escape_string($_POST['donate']);
				$chatbox = mysql_real_escape_string($_POST['chatbox']);
				$staff = mysql_real_escape_string($_POST['staff']);
				$newstitle = mysql_real_escape_string($_POST['newstitle']);
				$newsimage = mysql_real_escape_string($_POST['newsimage']);
				$news = mysql_real_escape_string($_POST['news']);
				$op1 = mysql_real_escape_string($_POST['op1']);
				$op2 = mysql_real_escape_string($_POST['op2']);
				$op3 = mysql_real_escape_string($_POST['op3']);
				//We check if there is no other user using the same username
				$dn = mysql_fetch_array(mysql_query('select count(*) as nb from users where username="'.$username.'"'));
				//We check if the username changed and if it is available
				if($dn['nb']==0 or $_POST['username']==$_SESSION['username'])
				{
					//We edit the user informations
					$update_q = "UPDATE users SET username = '$username', password = '$password', email = '$email', description = '$description', keywords = '$keywords', logo = '$logo', webclient = '$webclient', forums = '$forums', hiscores = '$hiscores', chatbox = '$chatbox', staff = '$staff', newstitle = '$newstitle', newsimage = '$newsimage', news = '$news', op1 = '$op1', op2 = '$op2', op3 = '$op3' WHERE id = ".mysql_real_escape_string($_SESSION['userid']);
                                                $update_action = mysql_query($update_q) or die ('ERROR! Unable to perform update<br>'.mysql_error().'<br><br>This error occured while atempting to run the following code:<br>'.$update_q);
					if (mysql_affected_rows() > 0) {
						//We dont display the form
						$form = false;
						//We delete the old sessions so the user need to log again
						unset($_SESSION['username'], $_SESSION['userid']);
?>
<div class="message">Your informations have successfuly been updated. You need to log again.<br />
<a href="connexion.php">Log in</a></div>
<?php
					}
					else
					{
						//Otherwise, we say that an error occured
						$form = true;
						$message = 'An error occurred while updating your informations.';
					}
				}
				else
				{
					//Otherwise, we say the username is not available
					$form = true;
					$message = 'The username you want to use is not available, please choose another one.';
				}
			}
			else
			{
				//Otherwise, we say the email is not valid
				$form = true;
				$message = 'The email you entered is not valid.';
			}
		}
		else
		{
			//Otherwise, we say the password is too short
			$form = true;
			$message = 'Your password must contain at least 6 characters.';
		}
	}
	else
	{
		//Otherwise, we say the passwords are not identical
		$form = true;
		$message = 'The passwords you entered are not identical.';
	}
}
else
{
	$form = true;
}
if($form)
{
	//We display a message if necessary
	if(isset($message))
	{
		echo '<strong>'.$message.'</strong>';
	}
	//If the form has already been sent, we display the same values
	if(isset($_POST['username'],$_POST['password'],$_POST['description'], $_POST['keywords'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3']))
	{
		$pseudo = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
		if($_POST['password']==$_POST['passverif'])
		{
			$password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8');
		}
		else
		{
			$password = '';
		}
		$email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
		$description = htmlentities($_POST['description'], ENT_QUOTES, 'UTF-8');
		$keywords = htmlentities($dnn['keywords'], ENT_QUOTES, 'UTF-8');
		$logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8');
		$webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8');
		$forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8');
		$hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8');
		$chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8');
		$staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8');
		$newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8');
		$newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8');
		$news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8');
		$op1 = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8');
		$op2 = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8');
		$op3 = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8');
	}
	else
	{
		//otherwise, we display the values of the database
		$q = "select username,password,email,description,keywords,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username= '{$_SESSION['username']}.'";
		$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
		$dnn = mysql_fetch_assoc($rs);
		$username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8');
		$password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8');
		$email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8');
		$description = htmlentities($dnn['description'], ENT_QUOTES, 'UTF-8');
		$keywords = htmlentities($dnn['keywords'], ENT_QUOTES, 'UTF-8');
		$logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8');
		$webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8');
		$forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8');
		$hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8');
		$chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8');
		$staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8');
		$newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8');
		$newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8');
		$news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8');
		$op1 = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8');
		$op2 = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8');
		$op3 = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8');
	}
	//We display the form
?>
<div class="content">
    <form action="edit_infos.php" method="post">
        You can edit your informations:<br />
        <div class="center">
            <label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo $username; ?>" /><br />
            <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" id="password" value="<?php echo $password; ?>" /><br />
            <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" id="passverif" value="<?php echo $password; ?>" /><br />
            <label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br />
            <label for="description">Webclient/Server Description</label><textarea name="description" id="description" rows="3" value="<?php echo $description; ?>"></textarea><br />
            <label for="keywords">Webclient/Server Tags<span class="small">(Seperate with comma's)</span></label><input type="text" name="keywords" id="keywords" value="<?php echo $keywords; ?>" /><br />
            <label for="logo">Website/Server Logo Link</label><input type="text" name="logo" id="logo" value="<?php echo $logo; ?>" /><br />
            <label for="webclient">Webclient Link</label><input type="text" name="webclient" id="webclient" value="<?php echo $webclient; ?>" /><br />
            <label for="forums">Forums Link</label><input type="text" name="forums" id="forums" value="<?php echo $forums; ?>" /><br />
            <label for="hiscores">Hiscores Link</label><input type="text" name="hiscores" id="hiscores" value="<?php echo $hiscores; ?>" /><br />
            <label for="chatbox">Chatbox Html</label><textarea name="chatbox" rows="3" id="chatbox" value="<?php echo $chatbox; ?>" ></textarea><br />
            <label for="staff">Staff Page Link</label><input type="text" name="staff" id="staff" value="<?php echo $staff; ?>" /><br />
            <label for="newstitle">News Article Title</label><input type="text" name="newstitle" id="newstitle" value="<?php echo $newstitle; ?>" /><br />
            <label for="newsimage">News Article Image Link<span class="small">(Displayed under title)</span></label><input type="text" name="newsimage" id="newsimage" value="<?php echo $newsimage; ?>" /><br />
            <label for="news">News Article</label><textarea name="news" rows="3" id="news" value="<?php echo $news; ?>" ></textarea><br />
<label for="op1">Optional Link #1</label><input type="text" name="op1" id="op1" value="<?php echo $op1; ?>" /><br />
<label for="op2">Optional Link #2</label><input type="text" name="op2" id="op2" value="<?php echo $op2; ?>" /><br />
<label for="op3">Optional Link #3</label><input type="text" name="op3" id="op3" value="<?php echo $op3; ?>" /><br />
            <input type="submit" value="Send" />
     </div>
    </form>
</div>
<?php
}
}
else
{
?>
<div class="message">To access this page, you must be logged.<br />
<a href="connexion.php">Log in</a></div>
<?php
}
?>
	<div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div>
</body>
</html>

Well, when you finish filling out form and click submit. Nothing happens, it just refreshes page and it doesn't say that it has updated.

The database its in is 'tools'

The table is 'users'

The user structure is like this:

id

username

password

email

description

keywords

ip

webclient

forums

hiscores

donate

logo

chatbox

staff

newstitle

newsimage

news

op1

op2

op3

 

All of them are 'varchar' except for email which is TEXT and id which is 'int'.

Btw out of curiosity do you have an extra PHP script that has login, logout, register, edit info, profile page?

Maybe i can use yours instead?

Anyway, thanks.

if you want me to write you a login script were going to need to start talking prices, I'll help you out for free, but I (and a lot of other people here) will chargeyou if you it all done for you  ;D.  let me look into the issue.

if you want me to write you a login script were going to need to start talking prices, I'll help you out for free, but I (and a lot of other people here) will chargeyou if you it all done for you  ;D.  let me look into the issue.

Okay thanks

I mean that there is condition within the code that sais "if this form was just posted and I am to display it again, display the form using the information that was just entered --or-- display the form with the info from the database"  I was asking which is being returned - the information that you input, or the database info.  This will help establish if the problem is with the recognition of the POST content or not.

 

anyway, I got to turn in for the night, I'll look back in on it in the morning.

Your big isset() statement near the start of your code is failing, probably because one of the field names is incorrect -

 

	//We check if the form has been sent
if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['description'], $_POST['keywords'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3']))

 

To test if a form has been submitted, you should test if one specific field is set, such as the submit button or use a hidden field with a specific name.

 

Your validation logic should test each data field and report which one(s) were left empty. that would help pin down which one of those doesn't match your form field names.

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.