Jump to content

Edit Information Form


JustinK101

Recommended Posts

Hey guys,

So I have a form which stores name, email, address, city, state, etc. The user fills in the form no problem. I use POST as the method.

Now I want to have the ability for the user to edit their information. So the issues is that all the fields values are equal to: <? echo $_POST['field_name'] ?> but I need the fields to be populated with the values stored in the mysql database. So I change the value to <? echo $row['field_value'] ?> which works, with one problem.

If they screw up a field or don't enter a required field the page reloads and displays an error message, but all the fields get populated with the values from the database instead of the values which they just updated, i.e. the $_POST['field_name']. See because the values are set to $row['field_name']. Basically I need to have all the values first populate from the database and then after that, they need to populate from $_POST['field_name']. I think. I may be way off here. Thanks for the help.
Link to comment
Share on other sites

[!--quoteo(post=356571:date=Mar 19 2006, 10:55 PM:name=JustinK101)--][div class=\'quotetop\']QUOTE(JustinK101 @ Mar 19 2006, 10:55 PM) [snapback]356571[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hey guys,

So I have a form which stores name, email, address, city, state, etc. The user fills in the form no problem. I use POST as the method.

Now I want to have the ability for the user to edit their information. So the issues is that all the fields values are equal to: <? echo $_POST['field_name'] ?> but I need the fields to be populated with the values stored in the mysql database. So I change the value to <? echo $row['field_value'] ?> which works, with one problem.

If they screw up a field or don't enter a required field the page reloads and displays an error message, but all the fields get populated with the values from the database instead of the values which they just updated, i.e. the $_POST['field_name']. See because the values are set to $row['field_name']. Basically I need to have all the values first populate from the database and then after that, they need to populate from $_POST['field_name']. I think. I may be way off here. Thanks for the help.
[/quote]

Try This It Worked For Me:

[code]
<?php
INCLUDE('header.php');

if ($_POST['firstname'] != "") {
    $firstname = htmlspecialchars($_POST['firstname']);
    mysql_query("UPDATE users SET firstname='$firstname' WHERE username='$username'") or die (mysql_error());
    $_SESSION['firstname'] = $firstname;
    $cname = "<li>Your First name</li>";
}
if ($_POST['lastname'] != "") {
    $lastname = htmlspecialchars($_POST['lastname']);
    mysql_query("UPDATE users SET lastname='$lastname' WHERE username='$username'") or die (mysql_error());
    $_SESSION['lastname'] = $lastname;
    $cname1 = "<li>Your Last name</li>";
}

if ($_POST['about'] != "") {
    $hist = nl2br(htmlspecialchars($_POST['hist']));
    mysql_query("UPDATE users SET about='$about' WHERE username='$username'") or die (mysql_error());
    $_SESSION['hist'] = $hist;
    $chist = "<li>About You</li>";
}

if ($_POST['webs'] != "http://") {
    $webs = htmlspecialchars($_POST['webs']);
    mysql_query("UPDATE users SET webs='$webs' WHERE username='$username'") or die (mysql_error());
    $_SESSION['webs'] = $webs;
    $cwebs = "<li>website URL</li>";
}
?>
<html><head><title>Change Profile Results</title></head><body>
<h1>Change Profile Results:</h1>
<?php
if (($cname) || ($cstyle) || ($chist) || ($cinfl) || ($copen) || ($cwebs)) {
    echo "The following items have been updated in your profile:<br /><ul>";
    if ($cname) {
        echo $cname;
    }
        if ($cname1) {
        echo $cname1;
    }

    if ($cstyle) {
        echo $cstyle;
    }
    if ($chist) {
        echo $chist;
    }
    if ($cinfl) {
        echo $cinfl;
    }
    if ($copen) {
        echo $copen;
    }
    if ($cwebs) {
        echo $cwebs;
    }
    echo "</ul><br />To view your updated profile, <a href=\"images.php\">click here</a>.";
} else {
    echo "Nothing in your profile has been changed.  <a href=\"images.php\">Click here</a> to return to your profile.";
}
?>
</body></html>
[/code]

Simply Have A Form Post The Variables To This php page and your good to go
Link to comment
Share on other sites

Hey Mike, I dont follow. :) LOL Sorry.

Here is my form action:

[code]
<form name="update_account" method="POST" action="<? $_SERVER['QUERY_STRING'] ?>">
[/code]

Here is my mysql querry to grab all the user information:
[code]
$sql = "SELECT title, first_name, last_name, company_name, mailing_address, city, state, zip, website, email_address, phone_number, fax_number, industry, username, password, UNIX_TIMESTAMP(date_created) as cdate, UNIX_TIMESTAMP(date_last_modified) as mdate, ip_who_created, ip_who_last_modified FROM accounts WHERE id = " . $_SESSION['session_id'] . "";

$result = mysql_query($sql);
$account = mysql_fetch_assoc($result);
[/code]

Then all my fields values are set to this:
<input.... value="<? echo $account['field_name']; ?>"..>
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.