Jump to content

Check user input, script is provided just need some help


maxtran2005

Recommended Posts

Hi, I have this script below.  I can't make it work correctly, it kept going to the else statement. 

emaillist.txt    contains email seperated by comma

<?php

if ($_SERVER['REQUEST_METHOD'] == "POST") {
        $email = strip_tags($email);
                       
                $str = strtoupper(file_get_contents("emaillist.txt"));
                        if (strpos($str, strtoupper($email)))
                {
                    $feedback = "You already subscribed.";
                    $subject = "Thank you";
                    $message = "$email and $feedback";
                    mail($email, $subject, $message);
                }
                        else
                {
                    $feedback = "You haven't subscribed yet.  We will add you into our mailing list.";
                    $subject = "Sorry";
                    $message = "$email and $feedback";
                    mail($email, $subject, $message);
                }
}

?>

<html>
<head>
  <title></title>
</head>
<body>


<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
   
    $email = $_POST['email'];
    echo("<p><b>The following message was sent to $email\n");

    }
    else {
?>


  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">
    <p>
    Email:
    <input type="text" name="email" size="25">
    </td>
    </tr>
      <input type="submit" value="Send Feedback">
      </table>
        </p>
  </form>


<?php } ?>

</body>
</html>
Change this line (in two places)
[code]<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
?>[/code]

to

[code]<?php
if (isset($_POST['submit'])) {
?>[/code]

and change this line
[code]
<input type="submit" value="Send Feedback">
[/code]

to

[code]
<input type="submit" value="Send Feedback" name="submit">
[/code]

These changes make it easier to check whether your form was submitted.

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.