Folks,
Look at this script below! Both conditions from the IF & ELSE get echoed!
If “Line 53!” gets echoed (IF), then “Line 58!” (ELSE) should not get echoed and vice versa.
Makes sense. Right ?
Look at the attached img for what is getting echoed!
Fireup your Lamp/Xampp/Wamp and feed this code and check it out on your LocalHost.
What a mystery! Right ?
PROBLEM IN THIS SNIPPET …
[code]
if(!isset($_POST[“$value_2”]) && empty($_POST[“$value_2”]))
{echo “Line 253!<br>”;//echo $_POST[‘form_question_label_required’];
//die(“Fill-in All required Form Fields that! Fields with asterisks * are required to be filled-in!”);
}
else
{
echo “$value_2<br>”; echo “Line 258!<br>”;
}
FULL CODE
[code]
<?php
?>
<!DOCTYPE HTML”>
<html>
<head>
<meta name=”viewport” content=”width-device=width, initial-scale=1″>
</head>
<body>
<?php
/*
session_start();
//$_session = ‘search’;
//echo session_id();
//echo $_session;
if(isset($_GET[‘session_type’]))
{
$session=$_GET[‘session’];echo $_session[‘session’];
}
else
{
die(“Invalid Session1!”);echo $_session[‘session’];
}
*/
/*
echo session_id();
session_start();
if(isset($_GET[‘session_type’]))
{
$_GET[‘session_type’];
}
else
{
die(“Invalid Session2”);
}
*/
session_start();
//if($_SESSION[‘session_step’] != ‘end’);
{
$_SESSION[‘session_step’] = ‘start’;
echo $_SESSION[‘session_step’]; echo “<br>”;
echo session_status(); echo “<br>”;
echo “Line 52<br>”;
if(isset($_GET[‘session_type’]) && !empty($_GET[‘session_type’]))
{
$_SESSION[‘session_type’] = $_GET[‘session_type’];
//echo session_id();
if(!function_exists($_SESSION[‘session_type’]))
{
die(“Invalid Session”);
}
else
{
$_SESSION[‘session_type’]();
echo “Line 63<br>”;
}
}
else
{
die(“Invalid Session”);
//echo session_id(); DELETE
}
function submit_personal_details()
{
$session_type = $_SESSION[‘session_type’];
$form_questions_labels[]=’Title’;
$form_questions_labels[]=’First Name’;
$form_questions_labels[]=’Middle Name’;
$form_questions_labels[]=’Surname’;
$form_questions_labels[]=’Gender’;
$form_questions_labels[]=’Age_Range’;
$form_questions_labels[]=’Marital Status’;
$form_questions_labels[]=’Working Status’;
$form_questions_labels[]=’Tos’;
$form_questions_labels_required[]=’Title’;
$form_questions_labels_required[]=’First Name’;
$form_questions_labels_required[]=’Surname’;
$form_questions_labels_required[]=’Gender’;
//$form_questions_labels_required[]=’Age_Range’;
$form_questions_labels_required[]=’Marital Status’;
$form_questions_labels_required[]=’Working Status’;
$form_questions_labels_required[]=’Tos’;
$text_fields_labels = array(‘First Name’,’Middle Name’,’Surname’);
$radio_buttons_labels = array(‘Gender’,’Tos’);
$drop_downs_labels = array(‘Marital Status’,’Working Status’);
/*
$i=1;
$options_radio_button_[$i] = array(‘Male’,’Female’,’Male To Female’,’Female To Male’);
$i=2;
$options_radio_button_[$i] = array(‘Yes’,’No’);
*/
/*
$i=1;
$options_drop_down_[$i] = array(‘Single’,’Married’,’Divorced’,’Widow’);
$i=2;
$options_drop_down_[$i] = array(‘Selfemployed’,’Employed’,’Unemployed’);
*/
//Gender Options
$i=1;
$options_radio_button_[$i][]=’Male’;
$options_radio_button_[$i][]=’Female’;
$options_radio_button_[$i][]=’Male To Female’;
$options_radio_button_[$i][]=’Female To Male’;
$total_options_radio_button_[$i] = count($options_radio_button_[$i]);//4
//Tos Options
$i=2;
$options_radio_button_[$i][]=’Yes’;
$options_radio_button_[$i][]=’No’;
$total_options_radio_button_[$i] = count($options_radio_button_[$i]);//2
//Marital Status Options
$i=1;
$options_drop_down_[$i][]=’Single’;
$options_drop_down_[$i][]=’Married’;
$options_drop_down_[$i][]=’Divorced’;
$options_drop_down_[$i][]=’Widow’;
$total_options_drop_down_[$i] = count($options_drop_down_[$i]);//4
//Working Status Options
$i=2;
$options_drop_down_[$i][]=’Selfemployed’;
$options_drop_down_[$i][]=’Employed’;
$options_drop_down_[$i][]=’Unemployed’;
$total_options_drop_down_[$i] = count($options_drop_down_[$i]);//3
$total_form_questions_labels = 9;
$total_form_questions_labels_required = 8;
$total_text_fields_labels = 3;
$total_radio_buttons_labels = count($radio_buttons_labels);//2
$total_drop_downs_labels = count($drop_downs_labels);//2
?>
<form action=”<?php echo $_SERVER[‘PHP_SELF’];?>?session_type=<?php echo $_SESSION[‘session_type’];?>” method=”post” enctype=”plain/text”>
<?php
foreach($form_questions_labels as $form_question_label) //Loop through the whole ‘Form Questions’ array.
{
$value = $form_question_label;
$value_1 = str_replace(” “,”_”,”$value”); //Replaced Spaces to Underscores.
$value_2 = strtolower(“$value_1”); //Replaced Upper Case to Lower Case.
//Check if current ‘Form Item’ is a ‘Text Field’ or not.
if(in_array(“$form_question_label”,$text_fields_labels)) //Current ‘Form Item’ proved to be a ‘Text Field’.
{
//Check if current ‘Form Item’ (Text Field) is a ‘required’ one or not.
if(in_array(“$form_question_label”,$form_questions_labels_required))//Current ‘Form Item’ (Text Field) proved to be a ‘required’ one.
{
//Added ‘*’ (asterisk) to indicate the ‘Text Field’ is a ‘required’ one.
echo “<label for=”$value_2”>$form_question_label *:</label>
<input type=”text” name=”$value_2″ placeholder=”$form_question_label”>”;
}
else
{
//Added no ‘*’ (asterisk) to indicate the ‘Text Field’ is NOT a ‘required’ one.
echo “<label for=”$value_2”>$form_question_label:</label>
<input type=”text” name=”$value_2″ placeholder=”$form_question_label”>”;
}
echo “<br>”;
}
//Check if current ‘Form Item’ is a ‘Radio Button’ or not.
if(in_array(“$form_question_label”,$radio_buttons_labels)) //Current ‘Form Item’ proved to be a ‘Radio Button’.
{
//Check if current ‘Form Item’ (Radio Button) is a ‘required’ one or not.
if(in_array(“$form_question_label”,$form_questions_labels_required))//Current ‘Form Item’ (Radio Button) proved to be a ‘required’ one.
{
//Added ‘*’ (asterisk) to indicate the ‘Radio Button’ is a ‘required’ one.
echo “<label for=”$value_2″>$form_question_label *:</label>”;
}
else
{
//Added no ‘*’ (asterisk) to indicate the ‘Radio Button’ is NOT a ‘required’ one.
echo “<label for=”$value_2″>$form_question_label:</label>”;
}
$i = 0;
foreach($radio_buttons_labels as $radio_button_label) //$radio_buttons_labels = (‘Gender’,’Tos’);
{
if($form_question_label == $radio_button_label) //eg. ‘Gender’.
{
$i++;
foreach($options_radio_button_[$i] as $option_radio_button_[$i])
{
echo “<input type=”radio” id=”$option_radio_button_[$i]” name=”$value_2″ value=”$option_radio_button_[$i]”>
<label_for=”$option_radio_button_[$i]”>$option_radio_button_[$i]</label>”;
}
echo “<br>”;
}
$i++;
}
}
//Check if current ‘Form Item’ is a ‘Drop Down’ or not.
if(in_array(“$form_question_label”,$drop_downs_labels)) //Current ‘Form Item’ proved to be a ‘Drop Down’.
{
//Check if current ‘Form Item’ (Drop Down) is a ‘required’ one or not.
if(in_array(“$form_question_label”,$form_questions_labels_required))//Current ‘Form Item’ (Drop Down) proved to be a ‘required’ one.
{
//Added ‘*’ (asterisk) to indicate the ‘Drop Down’ is a ‘required’ one.
echo “<label for=”$value_2″>$form_question_label *:</label>”;
}
else
{
//Added no ‘*’ (asterisk) to indicate the ‘Drop Down’ is NOT a ‘required’ one.
echo “<label for=”$value_2″>$form_question_label:</label>”;
}
$i = 0;
foreach($drop_downs_labels as $drop_down_label) //$drop_downs_labels = (‘Gender’,’Tos’);
{
if($form_question_label == $drop_down_label) //eg. ‘Gender’.
{
$i++;
echo “<select name=”$value_2″>”;
foreach($options_drop_down_[$i] as $option_drop_down_[$i])
{
echo “<option value=”$option_drop_down_[$i]”>$option_drop_down_[$i]</option>”;
}
echo “</select>”;
echo “<br>”;
}
$i++;
}
}
}
?>
<input type=”submit” name=”submit_personal_details” value=”Submit”>
<?php
//$current_function = __FUNCTION__;
//echo $current_function;
if($_SERVER[‘REQUEST_METHOD’] === ‘POST’)
{echo “Line 238<br>”;
if(isset($_POST[‘submit_personal_details’]) && $_SESSION[‘session_step’] != ‘end’)
{echo “Line 240<br>”;
//$_SESSION[‘session_step’] = ‘end’;
echo $_SESSION[‘session_step’];
foreach($form_questions_labels_required AS $form_question_label_required)
{
$value = $form_question_label_required;
$value_1 = str_replace(” “,”_”,”$value”); //Replaced Spaces to Underscores.
$value_2 = strtolower(“$value_1”); //Replaced Upper Case to Lower Case.
if(!isset($_POST[“$value_2”]) && empty($_POST[“$value_2”]))
{echo “Line 253!<br>”;//echo $_POST[‘form_question_label_required’];
//die(“Fill-in All required Form Fields that! Fields with asterisks * are required to be filled-in!”);
}
else
{
echo “$value_2<br>”; echo “Line 258!<br>”;
}
/*
if(!isset($_POST[‘first_name’]) && empty($_POST[‘first_name’]))
{echo “Line 247<br>”;echo $_POST[‘title’];
//die(“Fill-in All required Form Fields that! Fields with asterisks * are required to be filled-in!”);
}
else
{
echo “$value_2<br>”; echo “Line 252<br>”;
}
*/
}
$_SESSION[‘session_step’] = ‘end’;
echo $_SESSION[‘session_step’]; echo “<br>”;
echo “Line 273<br>”;
session_destroy();
echo session_status(); echo “<br>”; echo “Line 270<br>”;
}
}
}
}
?>
What do you make out of all this ?
Don’t ask me about the sessions. Unless they got something to do with this issue. Like start and destroy session lines got something to do with it.