Why my site dosent get php error (fields are missing !) (php)


hello guys i wanna know why my codes does not work with When it has to !
i made code with php that lead my visitor that if fields are empty error them a short msg but it does not work pls help me !


We would love to help you out… however, we need the source code, or a, a bare minimum, the link the the website that is getting the error/the website that isn’t working properly.


the website works but my php codes does not work !
im srsly tired of trying to figure out why its not working can i send u php codes now ?


Yes, you can send me php codes now :slight_smile:


this is for processmail.php

<?php foreach($_post as $key => $value)
{ $temp =is_array($value) ? $value :trim($value);
if (empty ($temp) && in_array($key,$required))
{ $missing[] =$key;
$errors []='';
${$key} ='';
}elseif (in_array($key,$expected))
{ ${$key} = $temp;} }


and this is for contact.php (only php parts)

include './title.php';
$missing = [];
if (isset ($_post ['send']))
{ $to = 'amirmhzali@gmail.com';
$subject ='feedback from amirali';
$expected =['name','email','comments'];
$required =['name','comments'];
require './processmail.php';
} ?>


And this is for error msg part (contact.php)

 <h2>Contact Us !</h2>
        <?php if ($missing || $errors) { ?>
        <p class = "warning">Please Fix The Iteam(s) indicated.</p>
        <?php } ?>
        <form  method="post" action="">
        <label for="name">Name: <?php if ($missing && in_array('name',$missing)){ ?>
        <span class = "warning">please enter your name !</span>
        <?php } ?></label><br>
        <input name="name" id ="name" type ="text" placeholder ="username"></input><br>
        <label for ="email">Email:<?php if ($missing && in_array('email', $missing)) { ?>
                        <span class="warning">Please enter your email address</span>
                    <?php } ?></label><br>
        <input name ="email" id="email" type ="text" placeholder ="Email"></input>
            <label for"comments">comments: <?php if ($missing && in_array('comments', $missing)) { ?>
                        <span class="warning">Please enter your comments</span>
                    <?php } ?></label><br>
            <textarea name ="comments" id="comments"></textarea>
            <input name ="send" type ="submit" value="send message">
           <?php if ($_POST) { print_r($_POST); } ?>


i hope you help me because i really need you
i trying to build website for my friend :slight_smile:


I don’t quite understand why you want to do that, if(is_array) return array; else return trim($string);
I don’t understand it because you don’t have any arrays in contact.php

Anyway, I see you use $_post once in processmail.php and once in contact.php (possibly more places, but these are the ones I noticed)
This is incorrect, $_post is not the same as $_POST (use $_POST) :slightly_smiling_face:

just a quick note before i continue, remove your mail from contact.php (here on the foum)