Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP form validation not working - several issues
    primarykey
    data
    text
    <p>At the moment I am trying to validate a form using PHP. The problem is, that even after entering something wrong, PHP interprets it as right. Obviously I don't now why, although I have an assumption. This is the code:</p> <pre><code>if(isset($_GET['contact'])){ // Validation functions // Name function validate_name(){ $name = $_POST['customer']; if(strlen($name) &gt; 0){ trim(mysql_real_escape_string($name)); return true; }else { return false; } } // Mail function validate_mail(){ $mail = $_POST['mail']; if(preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/', $mail) &amp;&amp; strlen($mail) &gt; 0){ return true; }else { return false; } } // Message function validate_message(){ $message = $_POST['message']; if(strlen($message) &gt; 0){ trim(mysql_real_escape_string($message)); return true; }else { return false; } } validate_name(); validate_mail(); validate_message(); if(validate_name == true &amp;&amp; validate_mail == true &amp;&amp; validate_message == true){ echo "Ok!"; }else{ echo "Error!"; } } </code></pre> <p>One thing I know is bad is this: <code>if(validate_name == true &amp;&amp; validate_mail == true &amp;&amp; validate_message == true){}</code>. But if I am not mistaken, this still works because PHP can handle something like this (PHP only gives a notice, not an error). But how to do it right, there must be a better way?</p> <p>The second this I found out is, that PHP basically calls the functions correct, but inside the functions the if-else is not working. Why? I don't understand this...</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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