Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:37:58+00:00 2026-06-07T12:37:58+00:00

I have a php page that I’m trying to simplify and am running into

  • 0

I have a php page that I’m trying to simplify and am running into some issues that I can’t get through alone. My form takes user data, posts to itself, validates that fields have been filled in, and then displays form contents/posts to a mysql database.

The issue I am having is that instead of having 20 if()/elseif statements I wanted to load the variable names into an array, loop through that array, and if a variable wasn’t populated in the form have it produce an error message. Unfortunately my code will display the error message regardless of whether the field has a value in it or not.

As an additional note, I can add the $ShippingCo to my form and echo it but the notice that it isn’t completed still shows up.

Also, if the script enters the if statement I’d like for it to stop executing the remainder of the page after the closing I’ve tried exit; without success.

Here is what I have:

<?php

$ShippingCo = $_POST['ShippingCo'];
$ShipAcct = $_POST['ShipAcct'];
$ShipService = $_POST['ShipService'];
$FOB = $_POST['FOB'];
$Terms = $_POST['Terms'];

$ENote[] = '$Terms';
$ENote[] = '$FOB';
$ENote[] = '$ShippingCo';
$ENote[] = '$ShipAcct';
$ENote[] = '$ShipService';

$Emessg[] = 'Shipping Terms';
$Emessg[] = 'FOB Method';
$Emessg[] = 'Shipping Company';
$Emessg[] = 'Shipping Account';
$Emessg[] = 'Shipping Service Type';


foreach ($ENote as $a => $b) {

if(!$$ENote[$a]){       //I intentionally put the '$$' in this line otherwise none of the messages show. . . with data in the variables or not.

$error = "Error!  Please Add the $Emessg[$a]!";
?>
<table width="800" align="center">
<tr>
<td align="center">

<h2>Sales Order Entry Form</h2>
</td>
</tr>
<tr>
<td align="center">
<h3>
<font color="red">
<?php
echo "$error";
?>
</font>
</h3>
</td>
</tr>
<tr>
<td align="center">
Please press back to properly complete the form</td>
</tr>
</table>

<?php
}
}
?>

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:38:00+00:00Added an answer on June 7, 2026 at 12:38 pm

    I suspect that the syntax $$ENote[$a] is probably being interpreted as ($$ENote)[$a] instead of $($ENote[$a]) (parenthesis are not legal syntax, just for demo).

    So I suggest an intermediate variable, or else complex syntax:

    foreach ($ENote as $a => $b) {
      $varname = $ENote[$a];
      if(!$$varname){
    

    or (not tested, just a hunch that it might work):

    foreach ($ENote as $a => $b) {
      if(!${$ENote[$a]}){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP page that I run every minute through a CRON job.
I have a PHP / Javascript page that automatically logs a user into different
My requirement is that i have a .php page that has to display some
I have a php page that parses some xml text. That text comes from
I have a PHP page that loads external content using other PHP files. I'm
i have a php page that redirects (if successful) to another php page like
I have a PHP page that returns a piece of HTML to set the
I have a PHP page that does a couple of different things depending on
I have a php page that takes in a bunch of url parameters and
I have a PHP page that queries a DB to populate a form for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.