Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7569191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:06:31+00:00 2026-05-30T15:06:31+00:00

This is a mailing list script. It works by itself without jquery but I

  • 0

This is a mailing list script. It works by itself without jquery but I am trying to adapt it to work with ajax. However, without success. When the $.sql part is commented out it returns the variables in the url string successfully. However, when I uncomment that part of the js file and introduce the PHP into things it simply refreshes the page with the email address still in the input box. By itself, the PHP works so I’m at a loss as to where I’m going wrong. Here’s what I have… any help would be appreciated.

Form :

<form name="email_list" action="" id="maillist_form">

<p><strong>Your Email Address:</strong><br/>
<input type="text" name="email" id="email" size="40">
<input type="hidden" name="sub" id="sub" value="sub">

<p><input type="submit" value="Submit Form" class="email_submit"></p>
</form>

JQuery :

$(function() {    
$('#maillist_form').submit(function() { 

    var email = $("input#email").val();  
                if (name == "") { 
                $("input#email").focus();  
                return false;
            }  
    var sub = $("input#sub").val();  
                if (name == "") {  
                $("input#sub").focus();  
                return false;
            }       

    var dataString = $("#maillist_form").serialize();

    //alert (dataString);return false;  
    $.ajax({  
        type: "POST",  
        url: "mailing_list_add2.php",  
        data: dataString,  
        success: function() {  
            $('#display_block')                      
            .hide()  
            .fadeIn(2500, function() {  
                $('#display_block');  
            }); 
        }  
    }); 
    return false; 
});

});

PHP :

<?php
// connects the database access information this file
include("mailing_list_include.php");

// the following code relates to mailing list signups only
if (($_POST) && ($_POST["sub"] == "sub")) {

if ($_POST["email"] == "") {
        header("Location: mailing_list_add2.php");
        exit;
    } else {
        // connect to database
        doDB();

        // filtering out anything that isn't an email address
        if ( filter_var(($_POST["email"]), FILTER_VALIDATE_EMAIL)  == TRUE) {
            echo '';
        } else {
            echo 'Invalid Email Address';
            exit;
        }

        // check that the email is in the database
        emailChecker($_POST["email"]);

        // get number of results and do action
        if (mysqli_num_rows($check_res) < 1) {
            // free result
            mysqli_free_result($check_res); 

            // cleans all input variables at once
            $email = mysqli_real_escape_string($mysqli, $_POST['email']);

            // add record
            $add_sql =  "INSERT INTO subscribers (email) VALUES('$email')";
            $add_res =  mysqli_query($mysqli, $add_sql)
                        or die(mysqli_error($mysqli));
            $display_block = "<p>Thanks for signing up!</p>";

            // close connection to mysql
            mysqli_close($mysqli);
        } else {
            // print failure message
            $display_block = "You're email address - ".$_POST["email"]." - is already subscribed.";
    }
}
}

?>

I won’t put the include code in here because I’m assuming it is correct – unless the introduction of the jquery means this needs to be adapted as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:06:32+00:00Added an answer on May 30, 2026 at 3:06 pm

    Your AJAX is not catching back the result:

    $.ajax({  
        type: "POST",  
        url: "mailing_list_add2.php",  
        data: dataString,  
        success: function(response) {  
            $('#display_block')                      
            .hide()  
            .fadeIn(2500, function() {  
                $('#display_block').html(response);   //just an example method. 
           //Are you sure the selector is the same? 
           //Can also be $(this).html(response);
        }  
    }); 
    

    And as noted by gdoron, there’s no “name” variable. Maybe you meant “email” and “sub”, respectively?

    PHP response, also, isn’t echoed back. Just put:

    echo $display_block;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently posted this question on the r-help mailing list but got no answers,
I posted this in the mailing list, but the reply I got wasn't too
I found this script attached to a thread in the fontforge-users mailing list .
I posted this on the pygame mailing list but maybe someone here will have
I actually posted this question to pjsip mailing list, but did not get any
According to this mailing list thread , Groovy's event handling support doesn't work for
I'm making a mailing list script that takes advantage of ajax (async=false) to send
This question came today in the manipulatr mailing list. http://groups.google.com/group/manipulatr/browse_thread/thread/fbab76945f7cba3f I am rephrasing. Given
This is a question brought up in a local user group mailing list at
Note: This question is also posted on the WiX Users mailing list . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.