Jump to content


Photo

Starting again - updating users details


  • Please log in to reply
4 replies to this topic

#1 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 18 August 2006 - 10:40 AM

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:

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();

Thanks,

G

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 18 August 2006 - 11:16 AM

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.
follow me on twitter @PHPsycho

#3 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 18 August 2006 - 11:58 AM

Ok so I now have:

 $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

I am still getting an undefined inded as before, I assume I have misunderstood your answer..

#4 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 18 August 2006 - 01:14 PM

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

if (isset($_POST['submit'])) 
{ 
    if (isset($_POST['test1'])) {echo 'you checked the Beautician checkbox';} 
    else {echo '';} 
} 

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

Thanks,
G

#5 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 18 August 2006 - 01:37 PM

Yeah.. you are still using $test1 in your query instead of $val!!!!!!!
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users