Well, I'm working on a news system and am having trouble with the Edit Profile page. For some reason, my code lines 25 and 75 are saying that mysql_fetch_assoc is being supplied with invalid arguments. The code can be found below. The thing is, the $_SESSION variables that the script calls are defined and match the MySQL data for the given fields. That's what strikes me as odd because I've never had a problem like that before. Other aspects of the system are working, like login and logout features...
<?php
/*************************************
* Chronicle v0.1 *
* Edit.Profile.php *
* ================================== *
* Copyright 2005 *
* Coded by Nite Phire *
* http://dissonance.ketsukaiten.net/ *
* nitephire@ketsukaiten.net *
*************************************/
/* EditProfile ()
This function allows a user to change their
own profile options, such as avatar, email
address, and password. */
function EditProfile () {
if (isset ($_POST['submit'])) {
GLOBAL $tableprefix;
$username = $_SESSION['username'];
$passcheck = md5 ($_POST['oldpass']);
$passquery = mysql_query ('SELECT password FROM ' . $tableprefix . 'chronicle_members WHERE username="' . $username . '"');
$password = mysql_fetch_assoc ($passquery);
if ($passcheck == $password['password']) {
if ($_POST['newpass1'] == '' &&
$_POST['newpass2'] == '') {
GLOBAL $tableprefix;
$userid = $_SESSION['userid'];
$username = $_POST['username'];
$useremail = $_POST['useremail'];
$userpic = $_POST['userpic'];
mysql_query ('UPDATE ' . $tableprefix . 'chronicle_members WHERE id="' . $userid . '" SET username="' . $username . '",
useremail="' . $useremail . '",
userpic="' . $userpic . '"');
} elseif ($_POST['newpass1'] !== '' &&
$_POST['newpass2'] !== '' &&
$_POST['newpass1'] == $_POST['newpass2']) {
GLOBAL $tableprefix;
$userid = $_SESSION['userid'];
$username = $_POST['username'];
$password = $_POST['newpass1'];
$useremail = $_POST['useremail'];
$userpic = $_POST['userpic'];
mysql_query ('UPDATE ' . $tableprefix . 'chronicle_members WHERE id="' . $userid . '" SET username="' . $username . '",
password="' . $password . '",
email="' . $useremail . '",
pic="' . $userpic . '"');
} else {
print ('Your passwords did not match. Go back and make sure both of the new password fields are identical.');
};
} else {
print ('You entered your password incorrectly. Please go back and fix it.');
};
} else {
GLOBAL $tableprefix;
$username = $_SESSION['username'];
$getquery = mysql_query ('SELECT * FROM ' . $tableprefix . 'chronicle_members WHERE username="' . $username . '"');
$userdata = mysql_fetch_assoc ($getquery);
$useremail = $userdata['email'];
$userpic = $userdata['pic'];
print ('
<span class="header">Edit Your Profile</span><br />
<br />
<form method="post" action="' . $_SERVER['REQUEST_URI'] . '">
<fieldset class="fullwidth">
<legend class="subheader">Username</legend>
This is the username that you login with and is displayed with all your posts. You may change it if you wish.<br />
<input type="text" name="username" class="formdata" value="' . $username . '" />
</fieldset>
<fieldset class="fullwidth">
<legend class="subheader">Old Password</legend>
Your password is required to change any profile information.<br />
<input type="password" name="oldpass" class="formdata" />
</fieldset>
<fieldset class="fullwidth">
<legend class="subheader">New Password</legend>
These fields are for changing your password. Leave them blank unless you wish to do so. If you do, type your new password in both fields.<br />
<input type="password" name="newpass1" class="formdata" />
<input type="password" name="newpass2" class="formdata" />
</fieldset>
<fieldset class="fullwidth">
<legend class="subheader">E-Mail Address</legend>
The email address is linked with the username in post display so that visitors may contact the news poster.<br />
<input type="text" name="useremail" class="formdata" value="' . $useremail . '" />
</fieldset>
<fieldset class="fullwidth">
<legend class="subheader">Picture URL</legend>
Input the URL to the picture you would like displayed with your posts as a default. When you post news, a similar field will be present in the form, with this URL as the default. You may change it for special posts in that form if you wish.<br />
<input type="text" name="userpic" class="formdata" value="' . $userpic . '" />
</fieldset>
<fieldset class="fullwidth">
<legend class="subheader">Add User</legend>
Make sure you have correctly entered your information before clicking Submit.<br />
<input type="submit" name="submit" value="Submit" class="submit" />
</fieldset>
</form>
');
};
};
?>