...

View Full Version : Looking for opinion



HDRebel88
07-28-2012, 08:44 PM
Looking to know if anybody sees any issues with this 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.

HDRebel88
07-28-2012, 09:17 PM
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
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum