/    Sign up×
Community /Pin to ProfileBookmark

Which Of These Is “Not Equal To Operator” ?

1.

[code]
if(!$current_value_matched == ‘TRUE’)
[/code]

2.

[code]
if($current_value_matched !== ‘TRUE’)
[/code]

3.

[code]
if(!$current_value_matched = ‘TRUE’)
[/code]

4.

[code]
if($current_value_matched != ‘TRUE’)
[/code]

I tried all of them and none of them give the results I want.
I reckon number 4 is correct.

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 13.2019 — Not knowing what you actually are comparing and what you want the result of the comparison to be, I cannot tell you which of those is "correct", other than #3 uses the = assignment operator, which probably is not what you want, since it is not a comparison. Another possible issue is that 'TRUE' is just a string literal, not the PHP reserved word for Boolean true.
Copy linkTweet thisAlerts:
@developer_webauthorDec 13.2019 — @NogDog#1611813

Ok. So, how to turn the 'TRUE' into 'boolean' ?
Copy linkTweet thisAlerts:
@developer_webauthorDec 13.2019 — @NogDog#1611813

I am trying to create a webform. Only difference is, I am not directly creating the html input fields by giving labels, input types and their name attributes. Instead, I am listing the input types and their labels on arrays.

Meaning, the php script would check the appropriate arrays and create the input types and figure whether the input type is a required one (*) or not based on the array values.

I get unlimited lines of errors. Like these:

<i>
</i>Notice: Undefined offset: 7 in C:xampphtdocstestrecord_add.php on line 133

Notice: Undefined offset: 7 in C:xampphtdocstestrecord_add.php on line 135

Notice: Undefined offset: 8 in C:xampphtdocstestrecord_add.php on line 133

Notice: Undefined offset: 8 in C:xampphtdocstestrecord_add.php on line 135

Notice: Undefined offset: 9 in C:xampphtdocstestrecord_add.php on line 133

Notice: Undefined offset: 9 in C:xampphtdocstestrecord_add.php on line 135

Notice: Undefined offset: 10 in C:xampphtdocstestrecord_add.php on line 133


Line 133 is this one:
<i>
</i>while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)


Short context of the code where the error occurs (lines 120-147):
<i>
</i>foreach($form_questions_labels as $value)
{
$required_current_count_match = 'False';
$textbox_current_count_match = 'False';
$textarea_current_count_match = 'False';
$radio_button_current_count_match = 'False';
$dropdown_current_count_match = 'False';

<i> </i> $current_value_matched = 'FALSE';
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = 'False';
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $required_current_count_match = 'TRUE';
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }


I do not understand where "offset 7" comes into play. There is no mention of 'offset 7' in my lines (132-133):

<i>
</i>$required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = 'False';
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)



Note that, the error starts from the very first 'while loop'.

Here is my code but not in full:

<i>
</i>&lt;?php
/*
This file/webpage allows the user to both create New Records and Edit Existing Records.
*/

//Connect to the database.
include("conn.php");

//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');

//TEXT BOX LABELS.
$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
//TEXT AREA LABELS.
$form_questions_textareas_labels = array('About Me');
//RADIO BUTTON LABELS.
$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
//DROPDOWN LABELS.
$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');

//RADIO BUTTONES AND THEIR OPTIONS
//'Gender' Options
$form_radio_button_number_[0] = array('Male','Female');
//'Marital Status' Options
$form_radio_button_number_[1] = array('Single','Married');
//'Working Status' Options
$form_radio_button_number_[2] = array('Working','Not Working');

//DROPDOWNS AND THEIR OPTIONS
//'Age Range' Options
$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
//'Education' Options
$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
//'Home Country' Options
$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');

//Creates the New/Edit Record Webform.
//Since this webform is used multiple times in this file, best to make a function that is easily reusable to call the webform.
function renderForm($first_name = '', $middle_name = '', $surname = '', $gender = '', $age_range = '', $education = '', $marital_status = '', $working_status = '', $profession = '', $work_title = '', $personal_email = '', $about_me = '', $home_area = '', $home_town = '', $home_neighbourhood = '', $home_council = '', $home_borough = '', $home_city = '', $home_county = '', $home_district = '', $home_region = '', $home_state = '', $home_country = '', $error = '', $id = '')
{
//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');

<i> </i>//TEXT BOX LABELS.
<i> </i>$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
<i> </i>//TEXT AREA LABELS.
<i> </i>$form_questions_textareas_labels = array('About Me');
<i> </i>//RADIO BUTTON LABELS.
<i> </i>$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
<i> </i>//DROPDOWN LABELS.
<i> </i>$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');

<i> </i>//RADIO BUTTONES AND THEIR OPTIONS
<i> </i>//'Gender' Options
<i> </i>$form_radio_button_number_[0] = array('Male','Female');
<i> </i>//'Marital Status' Options
<i> </i>$form_radio_button_number_[1] = array('Single','Married');
<i> </i>//'Working Status' Options
<i> </i>$form_radio_button_number_[2] = array('Working','Not Working');
<i> </i>
<i> </i>//DROPDOWNS AND THEIR OPTIONS
<i> </i>//'Age Range' Options
<i> </i>$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
<i> </i>//'Education' Options
<i> </i>$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
<i> </i>//'Home Country' Options
<i> </i>$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');
<i> </i>?&gt;
<i> </i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<i> </i>&lt;html&gt;
<i> </i>&lt;head&gt;
<i> </i>&lt;title&gt;
<i> </i>&lt;?php
<i> </i>if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i>{
<i> </i> echo "Edit Existing Personal Profile:";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "Add New Personal Profile:";
<i> </i>}
<i> </i>?&gt;
<i> </i>&lt;/title&gt;
<i> </i>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
<i> </i>&lt;/head&gt;
<i> </i>&lt;body&gt;
<i> </i>&lt;?php
<i> </i>if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i>{
<i> </i> echo "&lt;h2&gt;Edit Existing Personal Profile:&lt;/h2&gt;";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "&lt;h2&gt;Add New Personal Profile:&lt;/h2&gt;";
<i> </i>}
<i> </i>
<i> </i>if ($error != '')
<i> </i>{
<i> </i> echo "&lt;div style='padding:4px; border:1px solid red; color:red'&gt;" . $error. "&lt;/div&gt;";
<i> </i>}
<i> </i>?&gt;

<i> </i>&lt;div class="container"&gt;
<i> </i>&lt;form action="" method="post"&gt;
<i> </i>&lt;?php
<i> </i>if($id != '')
<i> </i>{
<i> </i> ?&gt;
<i> </i> &lt;input type="hidden" name="id" value="&lt;?php echo $id; //This $id is 'post id' &amp; 'user id'.?&gt;" /&gt;
<i> </i> &lt;p&gt;ID: &lt;?php echo $id; //This $id is 'post id' &amp; 'user id'. ?&gt;&lt;/p&gt;
<i> </i> &lt;?php
<i> </i>}
<i> </i>
<i> </i>foreach($form_questions_labels as $value)
<i> </i>{
<i> </i> $required_current_count_match = 'False';
<i> </i> $textbox_current_count_match = 'False';
<i> </i> $textarea_current_count_match = 'False';
<i> </i> $radio_button_current_count_match = 'False';
<i> </i> $dropdown_current_count_match = 'False';
<i> </i>
<i> </i> $current_value_matched = 'FALSE';
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = 'False';
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $required_current_count_match = 'TRUE';
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a TextBox or not.
<i> </i> //There are 16 TextBox questions: $form_questions_textboxes_labels = array().
<i> </i> $textbox_current_count = '0'; $textbox_count_end = '15'; $textbox_current_count_match = 'False';
<i> </i> while($value != $form_questions_textboxes_labels[$required_current_count] || $textbox_current_count != $textbox_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textboxes_labels[$textbox_current_count]")
<i> </i> {
<i> </i> $current_textbox_label_number = $textbox_current_count;
<i> </i> $textbox_current_count_match = 'True';
<i> </i> $textbox_current_count = $textbox_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textbox_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a TextArea or not.
<i> </i> //There is 1 TextArea question: $form_questions_textareas_labels = array().
<i> </i> $textarea_current_count = '0'; $textarea_count_end = '0'; $textarea_current_count_match = 'False';
<i> </i> while($value != $form_questions_textareas_labels[$required_current_count] || $textarea_current_count != $textarea_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textareas_labels[$textarea_current_count]")
<i> </i> {
<i> </i> $current_textarea_label_number = $textarea_current_count;
<i> </i> $textarea_current_count_match = 'True';
<i> </i> $textarea_current_count = $textarea_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textarea_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a RadioButton or not.
<i> </i> //There are 3 RadioButton questions: $form_questions_radio_buttons_labels = array().
<i> </i> $radio_button_current_count = '0'; $radio_button_count_end = '2'; $radio_button_current_count_match = 'False';
<i> </i> while($value != $form_questions_radiobuttons_labels[$required_current_count] || $radio_button_current_count != $radio_button_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_radio_buttons_labels[$radio_button_current_count]")
<i> </i> {
<i> </i> $current_radio_button_number = $radio_button_current_count;
<i> </i> $radio_button_current_count_match = 'True';
<i> </i> $radio_button_current_count = $radio_button_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $radio_button_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a DropDown or not.
<i> </i> //There are 3 DropDown questions: $form_questions_dropdowns_labels = array().
<i> </i> $dropdown_current_count = '0'; $dropdown_count_end = '2'; $dropdown_current_count_match = 'False';
<i> </i> while($value != $form_questions_dropdowns_labels[$required_current_count] || $dropdown_current_count != $dropdown_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_dropdowns_labels[$dropdown_current_count]")
<i> </i> {
<i> </i> $current_drop_down_number = $dropdown_current_count;
<i> </i> $dropdown_current_count_match = 'True';
<i> </i> $dropdown_current_count = $dropdown_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $dropdown_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == 'False' &amp;&amp; $textbox_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;input type="text" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2}; ?&gt;"/&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == 'False' &amp;&amp; $textarea_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;textarea name="&lt;?php echo $value_2;?&gt;" rows="10" cols="30"&gt;
<i> </i> &lt;?php
<i> </i> if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/textarea&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == 'False' &amp;&amp; $radio_button_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2};?&gt;" checked&gt;&lt;?php echo ${$value_2};?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == 'False' &amp;&amp; $dropdown_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;select id="&lt;?php echo $value_2;?&gt;" name="&lt;?php echo $value_2;?&gt;"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo ${$value_2};?&gt;" selected&gt;&lt;?php echo ${$value_2};?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/select&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == 'True' &amp;&amp; $textbox_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;input type="text" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2}; ?&gt;"/&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == 'True' &amp;&amp; $textarea_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;textarea name="&lt;?php echo $value_2;?&gt;" rows="10" cols="30"&gt;
<i> </i> &lt;?php
<i> </i> if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/textarea&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == 'True' &amp;&amp; $radio_button_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2};?&gt;" checked&gt;&lt;?php echo ${$value_2};?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == 'True' &amp;&amp; $dropdown_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;select id="&lt;?php echo $value_2;?&gt;" name="&lt;?php echo $value_2;?&gt;"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo ${$value_2};?&gt;" selected&gt;&lt;?php echo ${$value_2};?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/select&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i>}
<i> </i>?&gt;
<i> </i>&lt;input type="submit" name="submit" value="Submit" /&gt;
<i> </i>&lt;/form&gt;
<i> </i>&lt;/div&gt;

<i> </i>&lt;/body&gt;
<i> </i>&lt;/html&gt;
&lt;?php
}
Copy linkTweet thisAlerts:
@NogDogDec 13.2019 — > @developer_web#1611814 Ok. So, how to turn the 'TRUE' into 'boolean' ?

Just remove the quotes.
<i>
</i>if($something == true) {
Copy linkTweet thisAlerts:
@NogDogDec 13.2019 — > @developer_web#1611815 I do not understand where "offset 7" comes into play

Offset in this case means a numeric array index. So in this example...
<i>
</i>while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)

...$required_current_count has a value that is not currently an array index for the $form_questions_required_labels array. If that's not a bug, then you'll need to add a test to see if that array element is set (via the isset() function, most likely) before you try to actually use it.
Copy linkTweet thisAlerts:
@NogDogDec 13.2019 — > @NogDog#1611816 Just remove the quotes.

PS: You don't _have_ to use Boolean literals necessarily, but one benefit is that they are case-insensitive.
<i>
</i>11:18 $ /usr/bin/php -a
Interactive shell

php &gt; $foo = TRUE;
php &gt; $bar = true;
php &gt; if($foo === $bar) {
php { echo "samen";
php { } else {
php { echo "differentn";
php { }
same
php &gt; $foo = 'TRUE';
php &gt; $bar = 'True';
php &gt; if($foo == $bar) {
php { echo "samen";
php { } else {
php { echo "differentn";
php { }
different
php &gt;
Copy linkTweet thisAlerts:
@NogDogDec 13.2019 — Another PS: :)

If you assign true or false as Booleans to the variables/elements to be checked, you could then simply refer to them in an if statement without worrying about using the == or != operators (or === or !== strict-typing comparisons).
<i>
</i>if($some_boolean_value) { ... }
// ...is the same as...
if($some_boolean_value == true) { ... }

// and

if( ! $some_boolean_value) { ... }
// ...is the same as...
if($some_boolean_value == false) { ... }
Copy linkTweet thisAlerts:
@developer_webauthorDec 13.2019 — @NogDog#1611817

Even though I have used the if(isset) before on forms, I have never used it to test on arrays. And so, do you mind showing an example ?

<i>
</i>//Check if current Question is a * REQUIRED Question or not.
//There are 7 required questions: $form_questions_required_labels = array().
$required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)

Btw, the array has 7 values. initial offset starts at '0' and so the final offset is '6'. I have not written the code to go over the '6' and so I do not understand why the script is not stopping at offset '6' and why it is searching for offset '7' and beyond. Note the $required_current_count = 6. And not beyond 6.

See again ...

<i>
</i>&lt;?php
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');

$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');

foreach($form_questions_labels as $value)
{
$required_current_count_match = false;
$textbox_current_count_match = false;
$textarea_current_count_match = false;
$radio_button_current_count_match = false;
$dropdown_current_count_match = false;

<i> </i> $current_value_matched = false;
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $required_current_count_match = true;
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i>

How to solve this crisis ? I'll wait for your isset() example that checks array value offsets or whatever you meant.
Copy linkTweet thisAlerts:
@developer_webauthorDec 13.2019 — NogDog,

Do you mean I should be doing like this:
<i>
</i>if(isset($form_questions_required_labels[$required_current_count]))
{
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
{
if($value == "$form_questions_required_labels[$required_current_count]")
{
$current_required_label_number = $required_current_count;
$required_current_count_match = true;
$required_current_count = $required_count_end;

<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>

That way, I make sure the array offset does exist.

But like this NOT:
<i>
</i>//Check if current Question is a * REQUIRED Question or not.
//There are 7 required questions: $form_questions_required_labels = array().
$required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
{
if(isset($form_questions_required_labels[$required_current_count]))
{
if($value == "$form_questions_required_labels[$required_current_count]")
{
$current_required_label_number = $required_current_count;
$required_current_count_match = true;
$required_current_count = $required_count_end;

<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>

I am talking about the isset() to check the array value offset.

You know what. Neither code above solves the issue. The issue about the undefined offset 7 and 8 and so on, exists.

The script should not be searching for any array offsets over 6 as the initial offset starts at 0 and ends at 6 since there are 7 array values.
<i>
</i>$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');
Copy linkTweet thisAlerts:
@developer_webauthorDec 13.2019 — I had errors in my code. Fixed them but problem about undefined offset 7 and 8 and so on still exists.
<i>
</i>//Connect to the database.
include("conn.php");

//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');

//TEXT BOX LABELS.
$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
//TEXT AREA LABELS.
$form_questions_textareas_labels = array('About Me');
//RADIO BUTTON LABELS.
$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
//DROPDOWN LABELS.
$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');

//RADIO BUTTONES AND THEIR OPTIONS
//'Gender' Options
$form_radio_button_number_[0] = array('Male','Female');
//'Marital Status' Options
$form_radio_button_number_[1] = array('Single','Married');
//'Working Status' Options
$form_radio_button_number_[2] = array('Working','Not Working');

//DROPDOWNS AND THEIR OPTIONS
//'Age Range' Options
$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
//'Education' Options
$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
//'Home Country' Options
$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');

//Creates the New/Edit Record Webform.
//Since this webform is used multiple times in this file, best to make a function that is easily reusable to call the webform.
function renderForm($first_name = '', $middle_name = '', $surname = '', $gender = '', $age_range = '', $education = '', $marital_status = '', $working_status = '', $profession = '', $work_title = '', $personal_email = '', $about_me = '', $home_area = '', $home_town = '', $home_neighbourhood = '', $home_council = '', $home_borough = '', $home_city = '', $home_county = '', $home_district = '', $home_region = '', $home_state = '', $home_country = '', $error = '', $id = '')
{
//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');

<i> </i>//TEXT BOX LABELS.
<i> </i>$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
<i> </i>//TEXT AREA LABELS.
<i> </i>$form_questions_textareas_labels = array('About Me');
<i> </i>//RADIO BUTTON LABELS.
<i> </i>$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
<i> </i>//DROPDOWN LABELS.
<i> </i>$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');

<i> </i>//RADIO BUTTONES AND THEIR OPTIONS
<i> </i>//'Gender' Options
<i> </i>$form_radio_button_number_[0] = array('Male','Female');
<i> </i>//'Marital Status' Options
<i> </i>$form_radio_button_number_[1] = array('Single','Married');
<i> </i>//'Working Status' Options
<i> </i>$form_radio_button_number_[2] = array('Working','Not Working');
<i> </i>
<i> </i>//DROPDOWNS AND THEIR OPTIONS
<i> </i>//'Age Range' Options
<i> </i>$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
<i> </i>//'Education' Options
<i> </i>$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
<i> </i>//'Home Country' Options
<i> </i>$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');
<i> </i>?&gt;
<i> </i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<i> </i>&lt;html&gt;
<i> </i>&lt;head&gt;
<i> </i>&lt;title&gt;
<i> </i>&lt;?php
<i> </i>if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i>{
<i> </i> echo "Edit Existing Personal Profile:";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "Add New Personal Profile:";
<i> </i>}
<i> </i>?&gt;
<i> </i>&lt;/title&gt;
<i> </i>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
<i> </i>&lt;/head&gt;
<i> </i>&lt;body&gt;
<i> </i>&lt;?php
<i> </i>if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i>{
<i> </i> echo "&lt;h2&gt;Edit Existing Personal Profile:&lt;/h2&gt;";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "&lt;h2&gt;Add New Personal Profile:&lt;/h2&gt;";
<i> </i>}
<i> </i>
<i> </i>if ($error != '')
<i> </i>{
<i> </i> echo "&lt;div style='padding:4px; border:1px solid red; color:red'&gt;" . $error. "&lt;/div&gt;";
<i> </i>}
<i> </i>?&gt;

<i> </i>&lt;div class="container"&gt;
<i> </i>&lt;form action="" method="post"&gt;
<i> </i>&lt;?php
<i> </i>if($id != '')
<i> </i>{
<i> </i> ?&gt;
<i> </i> &lt;input type="hidden" name="id" value="&lt;?php echo $id; //This $id is 'post id' &amp; 'user id'.?&gt;" /&gt;
<i> </i> &lt;p&gt;ID: &lt;?php echo $id; //This $id is 'post id' &amp; 'user id'. ?&gt;&lt;/p&gt;
<i> </i> &lt;?php
<i> </i>}
<i> </i>
<i> </i>foreach($form_questions_labels as $value)
<i> </i>{
<i> </i> $required_current_count_match = false;
<i> </i> $textbox_current_count_match = false;
<i> </i> $textarea_current_count_match = false;
<i> </i> $radio_button_current_count_match = false;
<i> </i> $dropdown_current_count_match = false;
<i> </i>
<i> </i> $current_value_matched = false;
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
<i> </i> if(isset($form_questions_required_labels[$required_current_count]) &amp;&amp; $required_count_end)
<i> </i> {
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $next_required_label_number = $required_current_count++;
<i> </i> $required_current_count_match = true;
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a TextBox or not.
<i> </i> //There are 16 TextBox questions: $form_questions_textboxes_labels = array().
<i> </i> $textbox_current_count = '0'; $textbox_count_end = '15'; $textbox_current_count_match = false;
<i> </i> while($value != $form_questions_textboxes_labels[$textbox_current_count] || $textbox_current_count != $textbox_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textboxes_labels[$textbox_current_count]")
<i> </i> {
<i> </i> $current_textbox_label_number = $textbox_current_count;
<i> </i> $textbox_current_count_match = true;
<i> </i> $textbox_current_count = $textbox_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textbox_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a TextArea or not.
<i> </i> //There is 1 TextArea question: $form_questions_textareas_labels = array().
<i> </i> $textarea_current_count = '0'; $textarea_count_end = '0'; $textarea_current_count_match = false;
<i> </i> while($value != $form_questions_textareas_labels[$textarea_current_count] || $textarea_current_count != $textarea_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textareas_labels[$textarea_current_count]")
<i> </i> {
<i> </i> $current_textarea_label_number = $textarea_current_count;
<i> </i> $textarea_current_count_match = true;
<i> </i> $textarea_current_count = $textarea_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textarea_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a RadioButton or not.
<i> </i> //There are 3 RadioButton questions: $form_questions_radio_buttons_labels = array().
<i> </i> $radio_button_current_count = '0'; $radio_button_count_end = '2'; $radio_button_current_count_match = false;
<i> </i> while($value != $form_questions_radiobuttons_labels[$radio_button_current_count] || $radio_button_current_count != $radio_button_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_radio_buttons_labels[$radio_button_current_count]")
<i> </i> {
<i> </i> $current_radio_button_number = $radio_button_current_count;
<i> </i> $radio_button_current_count_match = true;
<i> </i> $radio_button_current_count = $radio_button_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $radio_button_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a DropDown or not.
<i> </i> //There are 3 DropDown questions: $form_questions_dropdowns_labels = array().
<i> </i> $dropdown_current_count = '0'; $dropdown_count_end = '2'; $dropdown_current_count_match = false;
<i> </i> while($value != $form_questions_dropdowns_labels[$dropdown_current_count] || $dropdown_current_count != $dropdown_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_dropdowns_labels[$dropdown_current_count]")
<i> </i> {
<i> </i> $current_drop_down_number = $dropdown_current_count;
<i> </i> $dropdown_current_count_match = true;
<i> </i> $dropdown_current_count = $dropdown_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $dropdown_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == false &amp;&amp; $textbox_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;input type="text" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2}; ?&gt;"/&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == false &amp;&amp; $textarea_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;textarea name="&lt;?php echo $value_2;?&gt;" rows="10" cols="30"&gt;
<i> </i> &lt;?php
<i> </i> if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/textarea&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == false &amp;&amp; $radio_button_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2};?&gt;" checked&gt;&lt;?php echo ${$value_2};?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == false &amp;&amp; $dropdown_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: &lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;select id="&lt;?php echo $value_2;?&gt;" name="&lt;?php echo $value_2;?&gt;"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo ${$value_2};?&gt;" selected&gt;&lt;?php echo ${$value_2};?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/select&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == true &amp;&amp; $textbox_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;input type="text" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2}; ?&gt;"/&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == true &amp;&amp; $textarea_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;textarea name="&lt;?php echo $value_2;?&gt;" rows="10" cols="30"&gt;
<i> </i> &lt;?php
<i> </i> if ($id != '') //This $id is 'post id' &amp; 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/textarea&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == true &amp;&amp; $radio_button_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo ${$value_2};?&gt;" checked&gt;&lt;?php echo ${$value_2};?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;input type="radio" name="&lt;?php echo $value_2;?&gt;" value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == true &amp;&amp; $dropdown_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?&gt;
<i> </i> &lt;div class="row"&gt;
<i> </i> &lt;div class="col-25"&gt;
<i> </i> &lt;label for="&lt;?php echo $value_2;?&gt;"&gt;&lt;b&gt;&lt;?php echo $value;?&gt;: *&lt;/b&gt;&lt;/label&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div class="col-75"&gt;
<i> </i> &lt;select id="&lt;?php echo $value_2;?&gt;" name="&lt;?php echo $value_2;?&gt;"&gt;
<i> </i> &lt;?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' &amp;&amp; $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even &lt;?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo ${$value_2};?&gt;" selected&gt;&lt;?php echo ${$value_2};?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;option value="&lt;?php echo $value_3;?&gt;"&gt;&lt;?php echo $value_3;?&gt;&lt;/option&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/select&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i>}
<i> </i>?&gt;
<i> </i>&lt;input type="submit" name="submit" value="Submit" /&gt;
<i> </i>&lt;/form&gt;
<i> </i>&lt;/div&gt;

<i> </i>&lt;/body&gt;
<i> </i>&lt;/html&gt;
&lt;?php
}
Copy linkTweet thisAlerts:
@NogDogDec 13.2019 — Could you just do something like this?
<i>
</i>foreach($form_questions_labels as $value) {
$required_current_count_match = false;
$textbox_current_count_match = false;
$textarea_current_count_match = false;
$radio_button_current_count_match = false;
$dropdown_current_count_match = false;
$current_value_matched = false;
// just use in_array() instead of a complicated while()?
if(in_array($value, $form_questions_required_labels)) {
$current_required_label_number = $required_current_count;
$required_current_count_match = true;
$required_current_count = $required_count_end; <br/>
$current_value_matched = true;
}

// whatever else happens after this...
}

However, in the bigger picture, and depending on things I don't know, I might consider refactoring things to use a single multi-dimension array that could be walked through via foreach(). If you need to add a question or change its required status, etc., you would then only have to edit this array (which could even be defined in a separate config file (JSON?) and imported into this script).
<i>
</i>$form_questions = array(
array(
'label' =&gt; 'First Name',
'required' =&gt; true,
'type' =&gt; 'text',
'name' =&gt; 'first_name'
),
array(
'label' =&gt; 'About Me',
'required' =&gt; false,
'type' =&gt; 'textarea',
'name' =&gt; 'about_me'
) // etc....
);
Copy linkTweet thisAlerts:
@developer_webauthorDec 13.2019 — @NogDog#1611823

Thanks!

I fogot about the if(in_array().

Thanks for reminding.

Btw, I haven't got into oop yet and so these are confusing '=>'.

Putting all your code in one line looks like this:
<i>
</i>$form_questions = array(array('label' =&gt; 'First Name','required' =&gt; true,'type' =&gt; 'text','name' =&gt; 'first_name'),array('label' =&gt; 'About Me','required' =&gt; false,'type' =&gt; 'textarea','name' =&gt; 'about_me') // etc....);

I have never seen any array looking like that and so guessing you rushed and made a typo. Do you mind fixing it so I can understand what you're trying to tell me ?

Show me sample in procedural style format. Beginner format.
Copy linkTweet thisAlerts:
@NogDogDec 13.2019 — > @developer_web#1611824 Putting all your code in one line looks like this:

I would highly recommend _not_ putting it all on one line. The PHP parser doesn't care one way or the other, but it's _much_ easier for us humans to maintain the code when it's on multiple lines -- and consistently indented -- versus one long line you can't even see without a bunch of horizontal scrolling. :)

In any case, the =&gt; operator is just an association of array key (on the left) to array value (on the right), and is not to be confused with the similar -&gt; OOP operator indicating the thing on the right is an attribute or method of the thing on the left. So, with my example array, you could reference the required status of the first name part of that array as $form_questions[0]['required']. You could therefore loop through each form element with:
<i>
</i>foreach($form_questions as $question) {
echo "&lt;label for='{$question['name']}'&gt;{$question['label']}";
if($question['required']) {
echo "*";
}
echo "&lt;/label&gt;n";
// some if/else or switch/case statement here based on $question['type']
// to control what form element type gets output...
}
Copy linkTweet thisAlerts:
@developer_webauthorDec 13.2019 — @NogDog#1611830

I just opened another thread regarding this same script but different issue:

https://www.webdeveloper.com/d/387053-fatal-error-cannot-use-isset-on-the-result-of-an-expression

As for this thread, it ain't finished yet. I will contact you again tomorrow (so stay tuned tomorrow) as nearly 2am here and so got to go.

Thanks for all the helps here.
Copy linkTweet thisAlerts:
@developer_webauthorDec 19.2019 — @NogDog#1611830

Thanks for the sample but I am still at procedural style and mysqli. Not at pdo or oop yet. I do not understand the "->" or the "=>".

Do you mind switching your code to the style I understand ? That way, I will be able to see what you are portraying.
Copy linkTweet thisAlerts:
@NogDogDec 19.2019 — There's not really any other style for defining a PHP array that uses string-type indexes (often called a "hash" in other languages). The only other alternative is to define each element in a separate command, and you really do not want to do that.
<i>
</i>// my previous example...
$form_questions = array(
array(
'label' =&gt; 'First Name',
'required' =&gt; true,
'type' =&gt; 'text',
'name' =&gt; 'first_name'
),
array(
'label' =&gt; 'About Me',
'required' =&gt; false,
'type' =&gt; 'textarea',
'name' =&gt; 'about_me'
)
);

// ...would become this ugly mess...
$form_questions = array();

$form_questions[0]['label'] = 'First Name';
$form_questions[0]['required'] = true;
$form_questions[0]['type'] = 'text';
$form_questions[0]['name'] = 'first_name';

$form_questions[1]['label'] = 'About Me';
$form_questions[1]['required'] = false;
$form_questions[1]['type'] = 'textarea';
$form_questions[1]['name'] = 'about_me';
Copy linkTweet thisAlerts:
@NogDogDec 19.2019 — PS: https://www.php.net/manual/en/language.types.array.php
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...