Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    124
    Thanks
    12
    Thanked 6 Times in 6 Posts

    Looking for opinion

    Looking to know if anybody sees any issues with this code:

    PHP Code:
    <?php
    session_start
    ();
    require 
    'db_select.php';
    require 
    'func.php';
    $test=array('area_code' => '555''phone3' => '555''phone4' => '5555''confirm_agreement' => 'yes''test_key' => ' ');
    $n=0;
    $test=array_map('trim'$test);
    foreach(
    $test as $key => $value){
    $
    $key=$value;
    $
    $key=sanitize($area51_db, $$key);


        if($
    $key==null || !isset($$key)){
        
    $error[$n]=1;
        }
        else{
        
    $error[$n]=0;
        }
        
    $n++;
    $_SESSION[$key]=$value;
    }


    $db_values="'".implode("', '"$test)."'";
    echo 
    "({$db_values})";
    $phone="(".$area_code.") ".$phone3." - ".$phone4." Ext. ".$ext."";
    echo 
    "<p> $phone <p>";

    print_r($error);

    echo 
    $_SESSION['area_code'];
    ?>
    Everything seems to be working fine, but just checking to see if anyone spots any potential issues. This is used to check a submitted form, generate an numeric error code of ones and zeros, and also generates the value insert part of my DB query.

    Just to note $test will eventually be replaced $_POST, and the $test is the foreach statement will be replaced with $_POST as well.
    Last edited by HDRebel88; 07-28-2012 at 09:54 PM.

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    124
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Actually I do have a problem now.

    I'm ending up with the following:
    Array ( [confirm_agreement] => yes [test_key] => [phone] => (555) 555 - 5555 Ext. [0] => )

    (`confirm_agreement`, `test_key`, `phone`, `0`)

    ('yes', '', '(555) 555 - 5555 Ext. ', '')

    Where is the numeric array key of "0" being introduced into the array?

    PHP Code:
    <?php
    session_start
    ();
    require 
    'db_select.php';
    require 
    'func.php';
    $test=array('area_code' => '555''phone3' => '555''phone4' => '5555'
    'confirm_agreement' => 'yes''test_key' => ' ');
    $n=0;
    $test=array_map('trim'$test);
    foreach(
    $test as $key => $value){
    $
    $key=$value;
    $
    $key=sanitize($area51_db, $$key);


        if($
    $key==null || !isset($$key)){
        
    $error[$n]=1;
        }
        else{
        
    $error[$n]=0;
        }
        
    $n++;
    $_SESSION[$key]=$value;
    }

    $phone="(".$area_code.") ".$phone3." - ".$phone4." Ext. ".$ext."";
    $test['phone']=$phone;
    array_push($test$phone_array);
    unset(
    $test['area_code']);
    unset(
    $test['phone3']);
    unset(
    $test['phone4']);
    unset(
    $test['ext']);
    print_r($test);
    $db_key_names=array_keys($test);
    $db_keys="`".implode("`, `"$db_key_names)."`";
    $db_values="'".implode("', '"$test)."'";
    echo 
    "<p>({$db_keys})</p>";
    echo 
    "<p>({$db_values})</p>";
    echo 
    "<p> $phone <p>";

    print_r($error);

    echo 
    $_SESSION['area_code'];
    ?>

    EDIT: Nevermind, it's because I didn't remove the array push, it was adding on a key of "0" with no value.
    Last edited by HDRebel88; 07-28-2012 at 10:21 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •