Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I tend to use isset($_POST['key1'], $_POST['key2'], $_POST['keyn']) as a starting point for determining if a form has had all required data submitted, along with testing things such as $_SERVER['REQUEST_METHOD'], $_SERVER['SERVER_PORT'], $_SERVER['REQUEST_URI']. Trimming is not harmful, but I just go for the jugular with preg_match($needle, $haystackenter) and make the regular expression non-greedyand non-buffer capturing. In short, why condition input when you can just make the test fail to being with?</p> <p>The language construct empty() works, but does it really matter if the value doesn't match the pattern you are looking for? As for performance, who can say if someone copied and pasted the Oxford English Dictionary what would happen in either case. </p> <pre><code>function ValidatePostKeyAndValue($input, $pattern, $length) { if(isset($input) &amp;&amp; preg_match($pattern, $input) &amp;&amp; ctype_print($input) &amp;&amp; strlen($input) &lt;= $length &amp;&amp; is_string($input)) { return true; } else { return false; } } </code></pre> <p>I could do more or less, depending on the situation. Boolean functions are your friends.</p> <p>As far your $data variable, I think it would be wise to consider if the wildcards _ and % might appear in your data. If so, addcslashes() can be used to target those characters in your string. Over all though, moving to mysqli() will save you from having to use mysql_select_db(). mysqli_connect() does this for you! Well worth the switch.</p>
 

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