Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    Colorado
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Message not returning

    I have a script that is executed when a user hits the submit button. For some reason, when the inputs are correct the page is not returning a thank you page but it is coming up with a blank page. When the inputs are left blank, it returns the correct page. Here is the code:
    PHP Code:
        if($n && $e)
        {
            
    $query "SELECT id FROM newsletter WHERE email='$e'";
            
    $result = @mysql_query($query);
            if(
    mysql_num_rows($result) == 0)
            {        
                
    $query "INSERT INTO newsletter (id, name, email)
                VALUES('$id', '$n', '$e')"
    ;
                
    $result = @mysql_query($query);
                if(
    $result)
                {
                    echo 
    "Thanks";
        
                    exit();
                }
                else
                {
                    
    $message "You could not be registered at this time. Please try again later.";
                }
            }
            else
            {
                
    $message "The E-Mail $email has already been entered into our database.";
            }
            
    mysql_close();
        }
        
    if(isset(
    $message))
    {
        echo 
    "$message";

    I'm stuck and don't understand why this is not working. Thanks for your help in advance!
    -Sk8er9547

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Is anything being added/selected from the database? Are those query's being executed? If they're not, then how are you getting the variables $n and $e? Are they from the url or a form?

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    Colorado
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the full script.....
    PHP Code:
    <?php
        
    require_once('mysql/mysql_list.php');
            
        function 
    escape_data ($data)
        {
            global 
    $dbc;
            if(
    ini_get('magic_quotes_gpc'))
            {
                
    $data stripslashes($data);
            }
            return 
    mysql_real_escape_string($data$dbc);
        }
        
        
    $message NULL;
    // These messages work fine
        
    if(empty($_POST['name']))
        {
            
    $n FALSE;
            
    $message "Please input your name!<br>";
        }
        else {
            
    $n escape_data($_POST['first_name']);
        }
        
        if(
    eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$"stripslashes(trim($_POST['email']))))
        {
            
    $e escape_data($_POST['email']);
        }
        else
        {    
            
    $e FALSE;
            
    $message .= "Please input a valid E-Mail address!<br>";
        }
        
        if(
    $n && $e)
        {
            
    $query "SELECT id FROM newsletter WHERE email='$e'";
            
    $result = @mysql_query($query);
            if(
    mysql_num_rows($result) == 0)
            {        
                
    $query "INSERT INTO newsletter (id, name, email)
                VALUES('$id', '$n', '$e')"
    ;
                
    $result = @mysql_query($query);
                if(
    $result)
                {
                    echo 
    "Thanks";
                    exit();
                }
    // These are the messages that are not working
                
    else
                {
                    
    $message "You could not be registered at this time. Please try again later.";
                }
            }
            else
            {
                
    $message "The E-Mail $email has already been entered into our database.";
            }
            
    mysql_close();
        }
        
    if(isset(
    $message))
    {
        echo 
    "$message";
    }        
    ?>
    -Sk8er9547

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Well thanks for that, but it still doesn't answer my questions. If the queries aren't being executed, then there's either a) something wrong with the query, or b) you're using the wrong variables, or c) you're using outdated code

    If the queries are being executed, then that's a complete different story

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    echo something in all your conditions and see if they work, as Nightfire said it should be something wrong with your queries, something that stops the flow of your script. It's not bad if you also posted your HTML form, you know, sometimes it happens we do some little mistakes in our form that we don't get anything in the PHP. No matter of how much experience you have, these little things happen!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •