Jump to content

Starting again - updating users details


genista

Recommended Posts

Hi all,

After messing around with this and making it complicated I have created a very simple script to allow a user to update their details. The problem sits with checkboxes that are not filled in come up as undefined indexes.

I have a page with html that allows the user to update, it then passes all the data to this form for processing, I need some way in here of posting the data even when it is empty:

[code=php:0]
Session start information ect at the top then,

<?php 
    //now we need to get the information passed into us from the edit data form 
    $first_name=addslashes($_POST['first_name']); 
    $maiden_name=($_POST['maiden_name']);
    $last_name=($_POST['last_name']);
    $address_line1=($_POST['address_line1']); 
    $address_line2=($_POST['address_line2']); 
    $town=($_POST['town']); 
    $county=($_POST['county']);
    $postcode=($_POST['postcode']);
    $daytime_phone=($_POST['daytime_phone']);
    $mobile_phone=($_POST['mobile_phone']);
    $evening_phone=($_POST['evening_phone']);
    $email_address=($_POST['email_address']);
$test1=($_POST['test1']);
$test2=($_POST['test2']);

$query = "UPDATE users SET first_name='$first_name', maiden_name='$maiden_name', last_name='$last_name', address_line1='$address_line1', address_line2='$address_line2', town='$town', county='$county', postcode='$postcode', etc etc

$result=mysql_query($query) or die("Could not insert data.".mysql_error()); 

    //$result represents the status of the operation true if it worked false if it failed 
    if($result){ 
        print "Your details have been sucesfully updated. You can go back to the <a href=members.php>index</a> page now."; 
    }else{ 
        print "Could not update data."; 
    } 

    //finally close the connection 
    mysql_close();
[/code]

Thanks,

G
Link to comment
Share on other sites

Check boxes and radio buttons are thopse little oddities that are NOT set if they are unchecked...

In your script where you look to set the values sent by these elements simply use..

$val = isset($_POST['chkbx1') ? $_POST['chkbx1'] : 'default';

you can then have set your default to whatever value you like and NOT kill the query.
Link to comment
Share on other sites

Ok so I now have:

[code=php:0]
$password=($_POST['password']);
    $first_name=($_POST['first_name']);
$last_name=($_POST['last_name']);
    $address_line1=($_POST['address_line1']);
    $address_line2=($_POST['address_line2']);
    $town=($_POST['town']);
    $county=($_POST['county']);
    $postcode=($_POST['postcode']);
    $daytime_phone=($_POST['daytime_phone']);
    $mobile_phone=($_POST['mobile_phone']);
    $email_address=($_POST['email_address']);
$val = isset ($_POST['test1']) ? ($_POST['test1']) : 'NULL';

Test1 being a checkbox.

Then we have

$query = "UPDATE suppliers SET first_name='$first_name', last_name='$last_name', password='$password', address_line1='$address_line1', address_line2='$address_line2', town='$town' , county='$county', postcode='$postcode', daytime_phone='$daytime_phone', mobile_phone='$mobile_phone', email_address='$email_address', test1='$test1', etc etc
[/code]

I am still getting an undefined inded as before, I assume I have misunderstood your answer..
Link to comment
Share on other sites

Ok so now I have used before the $query the following code, but still no joy:

[code=php:0]
if (isset($_POST['submit']))
{
    if (isset($_POST['test1'])) {echo 'you checked the Beautician checkbox';}
    else {echo '';}
}
[/code]

Any ideas as this is driving me nuts....

Thanks,
G
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.