Is there a simple way to do this?

Discussion in 'PHP' started by x0x, Feb 13, 2010.

  1. #1
    In this page, settings.php I have over 20 options that the user gets to modify. Right now it works like this:

    PHP:

    
    if ($first)
    {
        if($first != $user['field']){
    		
        if($first == 1){ 
    	$message .= "Enabled. ";
    	$set = 1;
    	}elseif($first == 2){
    	$message .= "Disabled. ";
    	$set = 2;
    	}
            $DB->query("UPDATE users SET field = '$set' WHERE id=$user[id]", __FILE__, __LINE__);
    	}
    PHP:



    HTML:

    <input type="radio" name="first" value="1" <?php if($user['field'] == 1){ echo "checked=1"; }?> /> On
    
    <input type="radio" name="first"  value="2" <?php if($user['field'] == 2){ echo "checked=1"; }?>/> Off 
    PHP:

    That's just a tiny fracture of the code so you can get the general idea. The other options are analogous.

    I think it's kinda annoying to check if the new submitted option is different from what is already in the database, and if is, then it will change it. Is there a better way to do this?
     
    x0x, Feb 13, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    danx10, Feb 13, 2010 IP