Jump to content

Edit Profile form and updating database.


W3C

Recommended Posts

OKay. So I made edited this editing profile php doc. I have the database and everything. When I hit update It says your profile has been updated. Then I go to the memberlist I click on the profile I just edited and it doesn't show waht I updated.

Code:
[code=php:0]
<title></title>
<?php
ob_start();
include("config.php");
if ($logged[username])
{
// the user is logged in!  We continue...
if (!$_POST[update])
{
// the form hasn't been submitted.  We continue...
$profile = mysql_query("SELECT * FROM family_users WHERE username = '$logged[username]'");
$profile = @mysql_fetch_array($profile);
// the above lines get the information so that it can be displayed in the html form.
echo("
<center><form method=\"POST\">
<table width=\"100%\">
<tr>
<td align=\"right\" width=\"25%\">
Location:
</td>
<td align=\"left\">
<input type=\"text\" size=\"25\" maxlength=\"25\" name=\"locate\" value=\"$profile[location]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
MSN Messenger:
</td>
<td align=\"left\">
<input size=\"25\" name=\"msn\" value=\"$profile[msn]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
AOL Messenger:</td>
<td align=\"left\">
<input size=\"25\" name=\"aim\"  value=\"$profile[aim]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
Email Address:</td>
<td align=\"left\">
<input size=\"25\"  name=\"email\" value=\"$profile[email]\"></td>
</tr>
<tr>

<td align=\"right\" width=\"25%\">
Kids:
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids1\" value=\"$profile[kids1]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids2\" value=\"$profile[kids2]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids3\" value=\"$profile[kids3]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids4\" value=\"$profile[kids4]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids5\" value=\"$profile[kids5]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids6\" value=\"$profile[kids6]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids7\" value=\"$profile[kids7]\"></td>
</tr>
<tr>

<td align=\"center\">
</td>
<td align=\"left\">
<input type=\"submit\" name=\"update\" value=\"Update\"></td>
</tr>
</table>
</form>
</center>");
}
else
{

$email = htmlspecialchars($_POST[email]);
$aim = htmlspecialchars($_POST[aim]);
$msn = htmlspecialchars($_POST[msn]);
$locate = htmlspecialchars($_POST[locate]);
$kids1 = htmlspecialchars($_POST[kids1]);
$kids2 = htmlspecialchars($_POST[kids2]);
$kids3 = htmlspecialchars($_POST[kids3]);
$kids4 = htmlspecialchars($_POST[kids4]);
$kids5 = htmlspecialchars($_POST[kids5]);
$kids6 = htmlspecialchars($_POST[kids6]);
$kids7 = htmlspecialchars($_POST[kids7]);
/*
$email = $_POST[email];
$aim = $_POST[aim];
$msn = $_POST[msn];
$locate = $_POST[locate];
$kids1 = $_POST[kids1];
$kids2 = $_POST[kids2];
$kids3 = $_POST[kids3];
$kids4 = $_POST[kids4];
$kids5 = $_POST[kids5];
$kids6 = $_POST[kids6];
$kids7 = $_POST[kids7];
*/
// the above lines get rid of all html.

$update = mysql_query
("UPDATE 'family_users' SET 'email' = '$email',
'msn' = '$msn',
'aim' = '$aim',
'location' = '$locate',
'kids1' = '$kids1',
'kids2' = '$kids2',
'kids3' = '$kids3',
'kids4' = '$kids4',
'kids5' = '$kids5',
'kids6' = '$kids6',
'kids7' = '$kids7' WHERE 'username' = '$logged[username]'");
$sql = "$email, $msn, $aim, $locate, $kids1, $kids2, $kids3, $kids4, $kids5, $kids6, $kids7";
echo ("Your profile has been updated!");
echo $sql;
// updates the information in the database.
}
}
else
{
// They aren't logged in!
echo ("<a href=\"login.php\">You must login</a>");
}
?>
[/code]
Thanks in advance,
Cheers
Link to comment
Share on other sites

Okay. I found some crazy solution. Solution:
By adding a username editing field and a value of "$profile[username]".(I also made the field disabled because if I tried to edit the username it wouldnt come up on the memberlist.)
Then I added "$username = htmlspecialchars($_POST[username]);".
Then I updated the db with adding "username = '$logged[username]".

code:
[code=php:0]
<title>Welcome. <?php $logged[username]; ?></title><?php
ob_start();
include("config.php");
if ($logged[username])
{
// the user is logged in!  We continue...
if (!$_POST[update])
{
// the form hasn't been submitted.  We continue...
$profile = mysql_query("SELECT * from family_users where username = '$logged[username]'");
$profile = mysql_fetch_array($profile);
// the above lines get the information so that it can be displayed in the html form.
echo("
<center><form method=\"POST\">
<table width=\"100%\">
<tr>
<td align=\"right\" width=\"25%\">
Username
</td>
<td align=\"left\">
<input disabled=\"disabled\" type=\"text\" size=\"25\" maxlength=\"25\" name=\"locate\" value=\"$profile[username]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
Last Name
</td>
<td align=\"left\">
<input size=\"25\" name=\"msn\" value=\"$profile[lname]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
First Name</td>
<td align=\"left\">
<input size=\"25\" name=\"aim\"  value=\"$profile[fname]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
Email Address</td>
<td align=\"left\">
<input size=\"25\"  name=\"email\" value=\"$profile[email]\"></td>
</tr>
<tr>

<td align=\"right\" width=\"25%\">
Kids:
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids1\" value=\"$profile[kids1]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids2\" value=\"$profile[kids2]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids3\" value=\"$profile[kids3]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids4\" value=\"$profile[kids4]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids5\" value=\"$profile[kids5]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids6\" value=\"$profile[kids6]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
</td>
<td align=\"left\">
<input size=\"25\" name=\"kids7\" value=\"$profile[kids7]\"></td>
</tr>
<tr>

<td align=\"center\">
</td>
<td align=\"left\">
<input type=\"submit\" name=\"update\" value=\"Update\"></td>
</tr>
</table>
</form>
</center>");
}
else
{
$email = htmlspecialchars($_POST[email]);
$fname = htmlspecialchars($_POST[fname]);
$lname = htmlspecialchars($_POST[lname]);
$username = htmlspecialchars($_POST[username]);
$kids1 = htmlspecialchars($_POST[kids1]);
$kids2 = htmlspecialchars($_POST[kids2]);
$kids3 = htmlspecialchars($_POST[kids3]);
$kids4 = htmlspecialchars($_POST[kids4]);
$kids5 = htmlspecialchars($_POST[kids5]);
$kids6 = htmlspecialchars($_POST[kids6]);
$kids7 = htmlspecialchars($_POST[kids7]);
// the above lines get rid of all html.
echo ("Your profile has been updated!");
$update = mysql_query("Update family_users set
email = '$email',
lname = '$lname',
fname = '$fname',
kids1 = '$kids1',
kids2 = '$kids2',
kids3 = '$kids3',
kids4 = '$kids4',
kids5 = '$kids5',
kids6 = '$kids6',
kids7 = '$kids7',
username = '$logged[username]'
where username = '$logged[username]'");
// updates the information in the database.
}
}
else
{
// They aren't logged in!
echo ("<a href=\"login.php\">You must login</a>");
}
?>
[/code]
Link to comment
Share on other sites

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.