Hi guys. Im currently working on the members section of my site. But im having fustrating problems trying to get my "edit profile" feature working!
When I fill the form, and submit it, it comes back true, as in it states that the user's profile has been updated successfully, but it hasnt!
Here the low down of the code:
If display.php detects $statusCheck equals to either admin or staff it includes the members.php template.
It also includes the following programs by default:
(in order of appearance):
dbinfo_and_queries.php
functions.php
script_strings.php
error_success.php
headers.php
profile.php: (called by display.php?pid=profile)
echo "<p><font size=\"2\" face=\"Tahoma\">Here you can view and edit your profile and other
info you submitted to us when you registered!</font></p>
<p><font size=\"2\" face=\"Tahoma\">Your details:</font></p>
<p><font size=\"2\" face=\"Tahoma\">";
$profile = array("<b>Username:</b> $username.",
"<b>E-Mail address:</b> " . $a_row["email"] . ".",
"<b>First Name:</b> " . $a_row["firstName"] . ".",
"<b>Last Name:</b> " . $a_row["lastName"] . ".",
"<b>Profile:</b><br>" . $a_row["aboutme"] . ".");
for($i=0;$i<sizeof($profile);$i++){
echo "<b>$i.</b> $profile[$i]<br>";
}
echo "</font></p>";
echo "<p><center>_ _ _ __________ _ _ _</center></p>";
echo "<font size=\"2\" face=\"Tahoma\">If you desire to change some or all of your account info, then amend the changes by filling in
the nessarsary form fields:</font>";
echo "<p><form name=\"edit_profile\" action=\"display.php?pid=profile\" method=\"post\">
<div align=\"left\">
<table width=\"98%\" border=\"0\">
<tr>
<td><font size=\"2\" face=\"Tahoma\"><b>1.</b> Username:</font></td>
<td><input name=\"username\" type=\"text\" value=\"$username\" style=\"background-color: #000000; color: #FFFFFF; font-family: Tahoma; font-size: 12px;\"></td>
</tr>
<tr>
<td><font size=\"2\" face=\"Tahoma\"><b>2.</b> E-Mail Address:</font></td>
<td><input name=\"email\" type=\"text\" value=\"" . $a_row["email"] . "\" style=\"background-color: #000000; color: #FFFFFF; font-family: Tahoma; font-size: 12px;\"></td>
</tr>
<tr>
<td><font size=\"2\" face=\"Tahoma\"><b>3.</b> First Name:</font></td>
<td><input name=\"firstName\" type=\"text\" value=\"" . $a_row["firstName"] . "\" style=\"background-color: #000000; color: #FFFFFF; font-family: Tahoma; font-size: 12px;\"></td>
</tr>
<tr>
<td><font size=\"2\" face=\"Tahoma\"><b>4.</b> Last Name:</font></td>
<td><input name=\"lastName\" type=\"text\" value=\"" . $a_row["lastName"] . "\" style=\"background-color: #000000; color: #FFFFFF; font-family: Tahoma; font-size: 12px;\"></td>
</tr>
<tr>
<td><font size=\"2\" face=\"Tahoma\"><b>5.</b> Profile:</font></td>
<td><textarea name=\"aboutme\" cols=\"40\" rows=\"5\" style=\"background-color: #000000; color: #FFFFFF; font-family: Tahoma; font-size: 12px;\">" . $a_row["aboutme"] . "</textarea></td>
</tr>
</table>
<p>
<input type=\"submit\" name=\"Submit\" value=\"Update\" style=\"background-color: #000000; color: #FFFFFF; font-family: Tahoma; font-weight: bold; font-size: 9px;\">
</p>
</div>
</form></p>";
The functions for varifying and inserting the data:
function verify_profile($formdata) {
$error = "";
$form_data = trim_data($formdata);
$user = $form_data['username'];
$insert_check = update_profile($formdata);
if ($insert_check != "true")
return($insert_check);
return("");
}
function update_profile($formdata) {
$error = "";
$myhost = "";
$myuser = "";
$mypass = "";
$mydb = "";
$email = $formdata['email'];
$firstName = $formdata['firstName'];
$lastName = $formdata['lastName'];
$username = $formdata['username'];
$aboutme = $formdata['aboutme'];
$mysql = mysql_connect($myhost, $myuser, $mypass);
if (!$mysql) {
$error = "Cannot connect to mySQL server";
return($error);
}
$mysqldb = mysql_select_db($mydb, $mysql);
if (!$mysqldb) {
$error = "Cannot open Database";
return($error);
}
if ($a_row = mysql_fetch_array($query0)){
$myquery = "UPDATE cph_members SET email = '$email', firstName = '$firstName', lastName = '$lastName', username = '$username', aboutme = '$aboutme' WHERE mid ='" . $a_row["mid"] . "'";
$result = mysql_query($myquery, $mysql);
if (!$result) {
$error = "Cannot run Query";
return $error;
}
}
return("true");
}
error_success.php:
if($Submit == "Update"){
$error = verify_profile($HTTP_POST_VARS);
if ($error == "")
$success = "Your profile was updated successfully!";
}
note that functions.php comes before profile.php, so the $a_row var doesnt have to be declared again.
Help appreciated. Thx.