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 12 of 12
  1. #1
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Insert user in good db, but check blacklist db first, help

    Hi

    Hope someone can help, I have a 2 databases, good customers and blacklisted (blocked) I'm trying to code so that the blacklist database is checked first, if the payer_email is in there then send email saying "go away"
    If the payer_email not in there then send email "hi, thanks for your order"
    It doesn't matter if the customer get's stored in the good database as long as the blacklist is checked.

    Below is the code, everything works until I add
    PHP Code:
    $query mysql_query("SELECT * FROM blacklist WHERE payer_email = '"$payer_email ."'");

    if (
    mysql_num_rows($query) > 0)


    Here's the full code
    PHP Code:
    <?php 

    $hostname 
    "213.17xxxxxxx"
    $db_user "xxxxx"
    $db_password "xxxxxx"
    $database "xxxxxxl"
    $db_table "tests"
    $db_table1 "blacklists";


    $db mysql_connect($hostname$db_user$db_password); 
    mysql_select_db($database,$db,$db_table1); 
    ?> 
    <html> 
    <head> 
    <title>insert test customers</title> 
    </head> 
    <body> 

    <?php 
    if (isset($_REQUEST['Submit'])) { 

    $sql "INSERT INTO $db_table(first_name,last_name,item_name,quantity,payment_type,payment_gross,payer_email) values ('".mysql_real_escape_string(stripslashes($_REQUEST['first_name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['last_name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['item_name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['quantity']))."','".mysql_real_escape_string(stripslashes($_REQUEST['payment_type']))."','".mysql_real_escape_string(stripslashes($_REQUEST['payment_gross']))."','".mysql_real_escape_string(stripslashes($_REQUEST['payer_email']))."')";
    if(
    $result mysql_query($sql ,$db)) { 

    //check blacklist database first

    $query mysql_query("SELECT * FROM blacklist WHERE payer_email = '"$payer_email ."'");



    if (
    mysql_num_rows($query) > 0)

    {

    $email $_REQUEST['xxxxx@hotmail.com'] ;
    $subject $_REQUEST['blacklisted sorry'] ;
    $message $_REQUEST['blacklisted sorry'] ;
    mail("xxxxxxx@hotmail.com""blacklisted sorry: $subject",
    $message"From: $email" );

    } else {
    //send good email
    $email $_REQUEST['xxxxx@hotmail.com'] ;
    $subject $_REQUEST['thanks for joining'] ;
    $message $_REQUEST['thanks for joining'] ;
    mail("xxxx@hotmail.com""thanks for joining: $subject",
    $message"From: $email" );
    echo 
    '<h1>Thank you</h1>Your information has been entered into our database<br><br><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRrgubFgupDxb71VuUpxL4t0vNivl3_I42sYm7a46-Cl-fwXiz2fQ"'
    } else { 
    echo 
    "ERROR: ".mysql_error(); 


    <
    h1>working code</h1>
    By <a href="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRrgubFgupDxb71VuUpxL4t0vNivl3_I42sYm7a46-Cl-fwXiz2fQ">cute</a><hr
    <
    form method="post" action=""
    first Name:<br
    <
    input type="text" name="first_name"
    <
    br
    Last Name:<br
    <
    input type="text" name="last_name"
    <
    br
    payers email <br
    <
    input type="text" name="payer_email"
    <
    br>What voucher item name: <br
    <
    input type="text" name="item_name"
    <
    br><br>Quantity <br
    <
    input type="text" name="quantity"
    <
    br><br>payment  echeck  or instant<br
    <
    input type="text" name="payment_type"
    <
    br><br>how much you paying eg6.99  or  12.49 or 17.99<br
    <
    input type="text" name="payment_gross"
    <
    br>
    <
    input type="submit" name="Submit" value="Submit"
    </
    form
    <?
    php 

    ?>
    Any help would be really well received..
    Thanks for your time.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,226
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Your if($result = mysql_query($sql ,$db)) has two else statements and that's not good. Also the same if will check the blacklist table and end if it's successful but will only give customers good email if it fails to add them to the db. Also not good.

    Check the blacklist table first. If successful(the customer email was in there) send a get lost message. If unsuccessful(the else statement) add them to the good db and send good email.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    lincon (04-01-2013)

  • #3
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks, will try that now.

    So is there a limit to how many else I can you.

    Eg: check blacklist, check quantity, then check another database.

    If one of them is not ok and I want to move on to the next I can only use 1 else?

    If yes what would I use to keep moving through different choices.

    Thanks once again.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,226
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Only 1 else per IF.
    But there is the "else if" Which can do a lot of if's and then there is also the switch statement.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,332
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    Quote Originally Posted by lincon View Post
    So is there a limit to how many else I can you.
    Yes you can only use one else per if conditional.

    If you need to test anything else, you may be better using a switch instead
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    lincon (04-03-2013)

  • #6
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks guys, not heard of that before, Only just worked out 'else'

    Will look in to it now.
    Thanks

  • #7
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Just thinking out loud.

    Would it not be possible to do this (not real code but showing what I mean) :

    if submit
    check database A <0
    then = send email to user

    else
    Go to another_page.php
    ------------------
    Then on the another_page.php

    it starts again but following on, so it opens up the database
    check database b <0
    then send different email

    else
    go to 3rd another page
    -----------------------

    and so on, so we could have as many else's as we want?

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,226
    Thanks
    23
    Thanked 606 Times in 605 Posts
    The following code does not work. It is just to show you a simple flow of things you want to do. All $_REQUESTs where changed to $_POSTs. The conditional statement to execute the php script uses a hidden field instead of the if (isset($_REQUEST['Submit'])) { line.

    You should read about MySQLi and use that instead of MySQL because it will be removed in next php version.

    This is approximately what you want:
    PHP Code:
    <?php 
    require ('Database Connection.php');

    if (isset(
    $_POST['Mirco']) == "junk") {  //SEE THE FORM ATTRIBUTES
    $payer_email $_POST['payer_email'];  // PUT ALL POST VALUES TO STRINGS HERE

    $hostname "213.17xxxxxxx"
    $db_user "xxxxx"
    $db_password "xxxxxx"
    $database "xxxxxxl"
    $db_table "tests"
    $db_table1 "blacklists";

    $query mysql_query("SELECT * FROM blacklist WHERE payer_email = '"$payer_email ."'") or die("Unable to connect to host ".mysql_error());

        if (
    mysql_num_rows($query) > 0)
        {
            
    $email $_POST['xxxxx@hotmail.com'] ;
            
    $subject $_POST['blacklisted sorry'] ;
            
    $message $_POST['blacklisted sorry'] ;
            
    mail("xxxxxxx@hotmail.com""blacklisted sorry: $subject",
            
    $message"From: $email" );
        }else{
            
    $sql "INSERT INTO $db_table
            (first_name,last_name,item_name,quantity,payment_type,payment_gross,payer_email) 
            values 
            ('"
    .mysql_real_escape_string(stripslashes($_POST['first_name']))."','".mysql_real_escape_string(stripslashes($_POST['last_name']))."','".mysql_real_escape_string(stripslashes($_POST['item_name']))."','".mysql_real_escape_string(stripslashes($_POST['quantity']))."','".mysql_real_escape_string(stripslashes($_POST['payment_type']))."','".mysql_real_escape_string(stripslashes($_POST['payment_gross']))."','".mysql_real_escape_string(stripslashes($_POST['payer_email']))."')";
            
    //send good email
            
    $email $_POST['xxxxx@hotmail.com'] ;
            
    $subject $_POST['thanks for joining'] ;
            
    $message $_POST['thanks for joining'] ;
            
    mail("xxxx@hotmail.com""thanks for joining: $subject",
            
    $message"From: $email" );
            echo 
    '<h1>Thank you</h1>Your information has been entered into our database<br><br>
            <img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRrgubFgupDxb71VuUpxL4t0vNivl3_I42sYm7a46-Cl-fwXiz2fQ">'

        }
    }
    ?> 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>insert test customers</title> 
    </head>

    <body>
    <h1>working code</h1>
    By <a href="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRrgubFgupDxb71VuUpxL4t0vNivl3_I42sYm7a46-Cl-fwXiz2fQ">cute</a><hr> 
    <form method="post" action="">
    <input type="hidden" name="Mirco" value="junk" />
    first Name:<br />
    <input type="text" name="first_name" /> 
    <br />
    Last Name:<br />
    <input type="text" name="last_name" /> 
    <br />
    payers email <br />
    <input type="text" name="payer_email" /> 
    <br />What voucher item name: <br />
    <input type="text" name="item_name" /> 
    <br /><br />Quantity <br />
    <input type="text" name="quantity" /> 
    <br /><br />payment  echeck  or instant<br />
    <input type="text" name="payment_type" /> 
    <br /><br />how much you paying eg: 6.99  or  12.49 or 17.99<br />
    <input type="text" name="payment_gross" /> 
    <br />
    <input type="submit" name="Submit" value="Submit" /> 
    </form>
    </body>
    </html>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    lincon (04-03-2013)

  • #9
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks once again, I see now it should have been post

    I've been looking at the switch mentioned above and seems fairly easy but It's not working with the way i'm doing it, anyone know what I've done wrong?
    PHP Code:
        if(isset($_POST['payer_email'])){
                
    $payer_email $_POST['payer_email'];
                
                switch (
    $payer_email) {
                
                case 
    1:
                    
    $query mysql_query("SELECT * FROM tests WHERE payer_email='$payer_email'");
                if(
    mysql_num_rows($query) > ) { //check if there is already an entry for that username
                        
    echo "Customer has been blacklisted!";
                    break;
                    
                case 
    2:
                  
    $query mysql_query("SELECT * FROM over_month_customer WHERE payer_email='$payer_email'");
                if(
    mysql_num_rows($query) > ) { //check if there is already an entry for that username
                        
    echo "Customer is in over month database";
                  break;
                  
                  Case 
    3
                   
    $query mysql_query("SELECT * FROM new_users WHERE payer_email='$payer_email'");
                if(
    mysql_num_rows($query) > ) { //check if there is already an entry for that username
                        
    echo "new users database";
                 default:
                 echo 
    "went to default";
                 break;
                 }    
        }
        
    mysql_close(); 
    Thanks once again for taking the time on a noob.

  • #10
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,226
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Your switch is not working because your 'case' is looking for a number but your switch statement isn't a number 'switch ($payer_email)'.

    In addition your switch statement has infinite possibilities, not a good thing.

    An example for after work:
    PHP Code:
    <?php
    if(isset ($_POST['joint'])){
        
    $beer $_POST['joint'];
        switch(
    $beer)
        {
            case 
    'tuborg';
                echo 
    'Good choice<br>';
                    die;
                break;    
            case 
    'carlsberg';
            echo 
    "You can do a lot better then this.<br>";
                    die;
            break;
            case 
    'heineken';
                echo 
    'Good choice<br>';
                    die;
                break;
            default;
                echo 
    'Please make a new selection...<br>';

        }
    }
    ?>

    What'll You Have?
    <form id="myform" method="POST" action="">
    <input type="radio" name="joint" value="heineken">Heineken<br>
    <input type="radio" name="joint" value="tuborg">Tuborg<br>
    <input type="radio" name="joint" value="carlsberg">Carlsberg<br>
    <input type="radio" name="joint" value="pabst">Pabst<br>
    <input type="submit" value="Place Order">
    </form>
    I have limited the choices. Also there is a difference in the switch if your using php or if your using javascript. Look it up to see.
    Last edited by sunfighter; 04-03-2013 at 02:01 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #11
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks,
    If I'm understanding right, I can't use switch because that needs a solid thing to look for, I don't know what email address will be submitted, thus I can't add that to swtich to look for.

    The other option then (if I understand above correct) is to use else if as mentioned above.

    Eg:
    PHP Code:
    if(isset($_POST['payer_email'])){
                
    $payer_email $_POST['payer_email'];
                

                
    $query mysql_query("SELECT * FROM blacklist WHERE payer_email='$payer_email'");
                if(
    mysql_num_rows($query) > ) { //check if there is already an entry for that username
                        
    echo "Customer has been blacklisted!";
                }else if{
                
    $query mysql_query("SELECT * FROM over_month_customer WHERE payer_email='$payer_email'");
                if(
    mysql_num_rows($query) > ) { //check if there is already an entry for that username
                        
    echo "over_month_customer!";
                }else{
                    
    mysql_query("INSERT INTO tests (first_name, payer_email) VALUES ('$first_name', '$payer_email')");
                    echo 
    "details stored in tests database!"
    It works perfect before I add the else if section, (just using if and else works perfect) but when I add the else if, I get error screen.

    Thank you for being understanding.

  • #12
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,226
    Thanks
    23
    Thanked 606 Times in 605 Posts
    You are missing most of the closing } brackets. They have to be there to mark the end of the statement.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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