Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is wrong with my PHP filtering system?
    primarykey
    data
    text
    <p>I have a simple filtering function for data that I'm receiving from POST, and for another variable (it will be part of the SESSION array, but in development is in an array of its own). The POST data is handled by the function exactly as expected, whereas the other variable, <code>$sess['iid']</code>, <strong><em>always</em></strong> fails. Why?</p> <p>I can work around this, but I hate not to understand why it's happening.</p> <p>The filtering function:</p> <pre><code>function filterNumber($fin) { if( ctype_digit( $fin ) ) { $fout = $fin; } else { $fout = 0; } return $fout; } </code></pre> <p>I am strict about naming variables, so the POST array is transferred into <code>$dirty[]</code>, and then <code>$clean[]</code> (for entry into the database) is produced by applying the appropriate filter to <code>$dirty[]</code>. The exact same sequence is applied to <code>$sess['iid']</code>.</p> <p>Examples of each stage:</p> <pre><code> $dirty['iid'] = $sess['iid']; $dirty['liverpool'] = $_POST['liverpool']; $clean['iid'] = filterNumber($dirty['iid']); $clean['liverpool'] = filterNumber($dirty['liverpool']); </code></pre> <p>The first step - <code>$sess['iid']</code> to <code>$dirty['iid]</code> - works, just as the POST variables do. </p> <p>But the second, <code>$dirty['iid']</code> to <code>$clean['iid']</code> via <code>filterNumber()</code>, results in a value of 0, regardless of what I put into <code>$sess['iid']</code>.<br> This also happens if I eliminate the <code>$dirty['iid']</code> step.</p>
    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