Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to assign values to $_POST[1] and $_POST[2] to begin with, I've done this for you but normally they would be populated from a form I assume?</p> <p>I'm not sure why you want to do this sort of thing: ${'field'.$key}, but I've left that part as is as I assume you must have a reason.</p> <p>Anyway I've modified your code a bit, see below.</p> <pre><code>$_POST['1'] = '&lt;h1&gt;variable 1&lt;/h1&gt;'; $_POST['2'] = '&lt;h2&gt;variable 2&lt;/h2&gt;'; foreach($_POST as $key =&gt; $value){ ${'field'.$key} = trim(addslashes(strip_tags($value))); echo "POST field info #". $key ." = ". ${'field'.$key}."&lt;br /&gt;"; } </code></pre> <p>The above code outputs:<br /> POST field info #1 = variable 1<br /> POST field info #2 = variable 2</p> <p>On a side note, using field names such as '1' and '2' is not very good. Try using something more descriptive but as I said above I assume you have a reason for doing this.</p> <hr> <p>UPDATE: You can still get this to work for any form even if you are using specific names for the form elements. I have added a few lines below as an example for you.</p> <pre><code>$_POST['email'] = 'example@example.com'; $_POST['password'] = 'hgbks78db'; $_POST['name'] = ''; foreach($_POST as $key =&gt; $value){ if($value==''){ echo 'POST field "'.$key . '" is empty&lt;br /&gt;'; /* I added the name of the field that is empty to an error array so you have a way of storing all blank fields */ $a_error[] = $key; } else{ echo 'POST field "'.$key . '" is not empty&lt;br /&gt;'; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload