Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is important to mention that your $volume, $gain, $treble, $middle and $bass will never actually be null as you have assigned a string to them in addition to the $_POST value. In addition you should always check if the $_POST values exist before trying to use them (or you will get an undefined notice message).</p> <p>Here is an example for a PHP version based on the code you had (untested, but should work fine).</p> <pre><code>&lt;?php function isValidRange( $value, $low = 0, $high = 65535) { // validate / cast value as int (add additional validation here $value = (int)$value; if ( $value &gt; $high || $value &lt; $low ) { // return null (not a valid value) return null; } // otherwise the value is valid so return it return $value; } // make sure the $name var is safe to use $name = ( isset($_POST['ampMod']) ) ? htmlentities($_POST['ampMod'],ENT_QUOTES,'UTF-8') : null; $volume = ( isset($_POST['volume']) ) ? isValidRange($_POST['volume']) : null; $gain = ( isset($_POST['gain']) ) ? isValidRange($_POST['gain']) : null; $treble = ( isset($_POST['treble']) ) ? isValidRange($_POST['treble']) : null; $middle = ( isset($_POST['middle']) ) ? isValidRange($_POST['middle']) : null; $bass = ( isset($_POST['bass']) ) ? isValidRange($_POST['bass']) : null; if( isset($volume) &amp;&amp; isset($gain) &amp;&amp; isset($treble) &amp;&amp; isset($middle) &amp;&amp; isset($bass) ) { echo "&lt;h3&gt; $name &lt;/h3&gt;"; echo "&lt;table&gt;&lt;tr&gt;"; echo "&lt;td&gt;Volume = $volume&lt;/td&gt;"; echo "&lt;td&gt;Gain = $gain&lt;/td&gt;"; echo "&lt;td&gt;Treble = $treble&lt;/td&gt;"; echo "&lt;td&gt;Middle = $middle&lt;/td&gt;"; echo "&lt;td&gt;Bass = $bass&lt;/td&gt;"; echo "&lt;/tr&gt;&lt;/table&gt;"; } else { echo ("Please try again. Values must be between 0-65535. 0=Off 65535=Full On 10&lt;br&gt;&lt;a href = \"ampchoice.php\"&gt;Click here to try again!&lt;/a&gt;");} ?&gt; </code></pre> <p>Lastly I would not recommend just relying on JavaScript to actually check if your values are safe to use (i.e. echo them out), but using js as a pre-warning to users and then properly validating with PHP is the best way to go.</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.
    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