Jump to content

[SOLVED] Adding DATA to an UPDATE form


stuart7398

Recommended Posts

Hi.

I'm trying to add the 'id' number to this 'UPDATE' form.

It doesn't work as I assume mysql thinks it's updating.

 

What do I use to enter the 'id' number or other data for that matter?

AND

Can if anyone spots faults / security issues or ways to reduce the code, which would be helpful.

 

Examples / suggestions / code all appreciated

Thanks, Stuart.

 

 

$username = "$SESS_MEMBER_ID"; 
if(isset($_POST['save'])){
  $firstname = mysql_real_escape_string($_POST['firstname']);
  $mobile = mysql_real_escape_string($_POST['mobile']);
  $phone_2 = mysql_real_escape_string($_POST['phone_2']);
  $login = mysql_real_escape_string($_POST['login']);
  mysql_query("UPDATE members SET firstname='$firstname', mobile='$mobile', phone_2='$phone_2', login='$login' WHERE member_id = '$SESS_MEMBER_ID'");
}

[b]Print "<div class='account'>";
Print "<br /><h3>My Account</h3>";
Print "Account Number:<span class='my_account'> ".$info['member_id']."</span>";[/b]

list($firstname, $mobile, $phone_2, $login) = mysql_fetch_array(mysql_query("SELECT firstname, mobile, phone_2, login FROM members WHERE member_id = '$SESS_MEMBER_ID'"));

Print "<div class='account'>";
Print '<br /><h3>Update Account</h3>';
Print "<h3>Personal Details</h3>";
Print '<form method="post" action="">';
Print '<p>First Name <span class="my_account"><input type="text" name="firstname" size="24" value="'.$firstname.'" /></span></p>';
Print '<p>Mobile <span class="my_account"><input type="text" name="mobile" size="24" value="'.$mobile.'" /></span></p>';
Print '<p>Phone 2 <span class="my_account"><input type="text" name="phone_2" size="24" value="'.$phone_2.'" /></span></p>';
Print '<p>Login <span class="my_account"><input type="text" name="login" size="24" value="'.$login.'" /></span></p>';
Print '<p> <input type="submit" value="Update" name="save" /></p>';
Print '</form></div>';


Print ' '.$firstname.' '.$mobile.' '.$login.' '.$phone_2.' ';

?>

--fenway edit: really, use code blocks!!!

Link to comment
Share on other sites

First, this line is not needed, because you don't use it:

$username = "$SESS_MEMBER_ID"; 

 

Change this:

mysql_query("UPDATE members SET firstname='$firstname', mobile='$mobile', phone_2='$phone_2', login='$login' WHERE member_id = '$SESS_MEMBER_ID'");

to this:

mysql_query("UPDATE members SET firstname='$firstname', mobile='$mobile', phone_2='$phone_2', login='$login' WHERE member_id = '$SESS_MEMBER_ID'")
  or die("Update error: ".mysql_error());

and it should provide you info on why it's not updating.

Link to comment
Share on other sites

Hi.

Thanks for you input.

 

I'm not looking to update the 'id' number, i'm looking to display it.

 

thanks.

 

 

Update Account

Account Number: user account id number

Personal Details

 

First Name      update field

Mobile            update field

Phone 2          update field

Address          update field

Link to comment
Share on other sites

Ah, try this:

 

<?php
if(isset($_POST['save'])){
  $firstname = mysql_real_escape_string($_POST['firstname']);
  $mobile = mysql_real_escape_string($_POST['mobile']);
  $phone_2 = mysql_real_escape_string($_POST['phone_2']);
  $login = mysql_real_escape_string($_POST['login']);
  mysql_query("UPDATE members SET firstname='$firstname', mobile='$mobile', phone_2='$phone_2', login='$login' WHERE member_id = '$SESS_MEMBER_ID'")
    or die("Update error: ".mysql_error());
}

list($member_id,$firstname, $mobile, $phone_2, $login) = mysql_fetch_array(mysql_query("SELECT member_id, firstname, mobile, phone_2, login FROM members WHERE member_id = '$SESS_MEMBER_ID'"));

print "<div class='account'>";
print "<h3>My Account</h3>";
print "Account Number:<span class='my_account'> ".$member_id."</span>";
print "<div class='account'>";
print '<h3>Update Account</h3>';
print "<h3>Personal Details</h3>";
print '<form method="post" action="">';
print '<p>First Name <span class="my_account"><input type="text" name="firstname" size="24" value="'.$firstname.'" /></span></p>';
print '<p>Mobile <span class="my_account"><input type="text" name="mobile" size="24" value="'.$mobile.'" /></span></p>';
print '<p>Phone 2 <span class="my_account"><input type="text" name="phone_2" size="24" value="'.$phone_2.'" /></span></p>';
print '<p>Login <span class="my_account"><input type="text" name="login" size="24" value="'.$login.'" /></span></p>';
print '<p> <input type="submit" value="Update" name="save" /></p>';
print '</form></div>';
?>

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.