Skip to main content

Forums

This topic contains 4 replies, has 0 voices, and was last updated by  deadlow 7 years, 6 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33619

    deadlow
    Member

    Ok, so I am learning PHP and having trouble with some basic code. I have a text box with a submit button to enter an email address for a mailing list. I want the the code to check to see if anything has been filled out and if so enter it into the database, at the same time check to see if that email address has already been submitted. The code I have written just keeps adding new email addresses even if the field is blank, what am I doing wrong? I have supplied the code below:

    < ?php $email = mysql_real_escape_string($_POST); if (isset($email)) {
    mysql_query(“INSERT INTO users (email)
    VALUES (‘$email’)”);
    echo “Success!”;
    } else {
    echo “Please enter a valid email address.”;
    }

    ?>

    #83876

    deadlow
    Member

    *This part of the code provided is supposed to check if the field is blank

    #83877

    stevendeeds
    Member
    #83878

    Billy
    Participant

    to check if it’s blank, just do:

    < ?php
    $email = mysql_real_escape_string($_POST);

    if ($email) {
    *Rest of code*
    } else {
    echo 'Please fill all fields';
    }
    ?>
    #83882

    deadlow
    Member

    That worked cyneWATCH, thanks for that. Why would taking the isset out make it work? I kinda figured that adding an isset would test wether is was there or not like a boolean?

    stevendeeds, thanks for that link I am def. gonna go through that one…

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star