Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Simple PHP Validation Help?

  1. #11
    Join Date
    Jan 2007
    Posts
    82
    Thanks
    30
    Thanked 18 Times in 17 Posts

    Default

    Ok I made some changes and still have erros.

    Here's the form:
    Code:
     <form name="raffle" action="http://n2flash.com/raffle.php" method="post">
            <input name="code" maxlength="25" size="20" type="text"><br>
    
            <input value="Submit" type="submit">
      </form>
    Here's the modified code:
    PHP Code:
    <?php
    $usercode 
    $_POST['code'];
    $realcode = array('1''2''3''4''5');
    $match "false";

    foreach (
    $realcode as $value)
    {
    if(
    strcasecmp($realcode[$value], $usercode) == 0)
    {
    $match "true";
    }
    }

    if(
    $match == "true")
    {
            
    $to "info@n2flash.com";
            
    $subject "Raffle Code";
            
    $email "info@n2flash.com";
            
    $message $_REQUEST['code'] ;
            
    $headers "From: $email";
            
    $sent mail($to$subject$message$headers) ;
            if(
    $sent)
            {
    header'Location: http://www.n2flash.com/success.html' ) ; }
            else
            {
    header'Location: http://www.n2flash.com/error.html' ) ; }
    }
    else
    {
    header'Location: http://www.n2flash.com/error.html' ) ;
    }

    ?>
    Still producing the same error. submitting a blank form directs to success page with an email generated. Any value directs to error page with no email sent.

    Mind boggling!

  2. #12
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    hmmm...I'm starting to suspect that it might be storing the numbers in your array as numbers and not as a string so try changing the if statement to this:

    Code:
    if ($realcode[$value] == $usercode)
    if that makes it work then it is just the fact that your array has integer values and we were trying to string compare them.
    What is obvious to you might not be to another.


    My Site

  3. The Following User Says Thank You to Moshambi For This Useful Post:

    tonyking (11-02-2008)

  4. #13
    Join Date
    Jan 2007
    Posts
    82
    Thanks
    30
    Thanked 18 Times in 17 Posts

    Default

    Lol, this is making no sense to me but check this out...

    Now with this code:
    PHP Code:
    <?php
    $usercode 
    $_POST['code'];
    $realcode = array('1''2''3''4''5');
    $match "false";

    foreach (
    $realcode as $value)
    {
    if (
    $realcode[$value] == $usercode)
    {
    $match "true";
    }
    }

    if(
    $match == "true")
    {
            
    $to "info@n2flash.com";
            
    $subject "Raffle Code";
            
    $email "info@n2flash.com";
            
    $message $_REQUEST['code'] ;
            
    $headers "From: $email";
            
    $sent mail($to$subject$message$headers) ;
            if(
    $sent)
            {
    header'Location: http://www.n2flash.com/success.html' ) ; }
            else
            {
    header'Location: http://www.n2flash.com/error.html' ) ; }
    }
    else
    {
    header'Location: http://www.n2flash.com/error.html' ) ;
    }

    ?>

    I submit nothing, and it's a sucess, with email.
    I submit 1, it fails no email.
    I submit 2, it works with an email???
    Same for 3, 4 and 5. works and sends an email.
    Just for giggles I submitted xx, and it failed.

    I have no clue why, but I hope you do! lol

  5. #14
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    lol wtf that is weird....I just noticed that you have this:

    Code:
    if($sent)
            {header( 'Location: http://www.n2flash.com/success.html' ) ; }
            else
            {header( 'Location: http://www.n2flash.com/error.html' ) ; }
    Now I am just wondering if this is the same that you are doing for the else
    part of the if($match == "true) statement. I don't think it would be making a problem, but with the luck we've been having who knows at this point...
    What is obvious to you might not be to another.


    My Site

  6. The Following User Says Thank You to Moshambi For This Useful Post:

    tonyking (11-02-2008)

  7. #15
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Lol, restart! Start your code over again! Thats defiantly the sign to restart!! (Lol, jk theres probably an explanation, or not. I suggest restarting on it though)
    Clean your code:
    PHP Code:
    <?php
      $usercode 
    $_POST['code'];
      
    $realcode = array('1''2''3''4''5');
      
    $match "false";
      
      foreach (
    $realcode as $value) {
          if (
    strcasecmp($realcode[$value], $usercode) == 0) {
              
    $match "true";
          }
      }
      
      if (
    $match == "true") {
          
    $to "info@n2flash.com";
          
    $subject "Raffle Code";
          
    $email "info@n2flash.com";
          
    $message $_REQUEST['code'];
          
    $headers "From: $email";
          
    $sent mail($to$subject$message$headers);
          if (
    $sent) {
              
    header('Location: http://www.n2flash.com/success.html');
          } else {
              
    header('Location: http://www.n2flash.com/error.html');
          }
      } else {
          
    header('Location: http://www.n2flash.com/error.html');
      }
    ?>
    Jeremy | jfein.net

  8. #16
    Join Date
    Jan 2007
    Posts
    82
    Thanks
    30
    Thanked 18 Times in 17 Posts

    Default

    Well this is depressing, I changed the values to 5 digits, aa592.. bb592... etc and nothing works right.

    Why do I even bother with php

    >.<

  9. #17
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    OK I GOT IT!

    Sorry I should have done this earlier, but I fired up my XAMPP and started testing it.

    so now here is what I got:

    Code:
    <?php
    $usercode = $_POST['code'];
    $realcode = array('1', '2', '3', '4', '5');
    $match = "false";
    
    for($i = 0; $i < count($realcode); $i++)
    {
    	if($realcode[$i] == $usercode)
    	{
    		$match = "true";
    	}
    }
    
    
    if($match == "true")
    {
            echo "Matched";
    }
    else
    {
    	echo "did not match";
    }
    
    ?>
    Now just enter in your email stuff in the same section you were before.
    I tested it on a couple numbers and it printed "Match" and also it does not match if you leave it blank now...

    Hope this works for you now...
    What is obvious to you might not be to another.


    My Site

  10. The Following User Says Thank You to Moshambi For This Useful Post:

    tonyking (11-02-2008)

  11. #18
    Join Date
    Jan 2007
    Posts
    82
    Thanks
    30
    Thanked 18 Times in 17 Posts

    Default

    It works! The input is case sensitive but at this point WHO CARES! IT WORKS! lol

    Here's the final code I tested:
    PHP Code:
    <?php
    $usercode 
    $_POST['code'];
    $realcode = array('1XB4''2XB5''3GG''4778''5');
    $match "false";

    for(
    $i 0$i count($realcode); $i++)
    {
        if(
    $realcode[$i] == $usercode)
        {
            
    $match "true";
        }
    }


    if(
    $match == "true")
    {
          
    $to "info@n2flash.com";
          
    $subject "Raffle Code";
          
    $email "info@n2flash.com";
          
    $message $_REQUEST['code'];
          
    $headers "From: $email";
          
    $sent mail($to$subject$message$headers);
          if (
    $sent) {
              
    header('Location: http://www.n2flash.com/success.html');
          } else {
              
    header('Location: http://www.n2flash.com/error.html');
          }
    }
    else
    {
        
    header('Location: http://www.n2flash.com/error.html');
    }

    ?>
    I will play with it some more tonight and see if I can understand more of how it's actually working. Thanks for all your help and prompt replies Moshambi!

  12. #19
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    Hey no problem man sorry it was such a drag at first! lol at least we got through it. Oh and btw to help out with the case sensitive issue just do this:

    Code:
    $usercode = strtoupper($_POST['code']);
    that will convert it to all uppercase, if you want lowercase it is strtolower();

    Also if you would like me to explain to you how each of the parts is working I would have no problem helping to try and help you understand it. Just let me know
    What is obvious to you might not be to another.


    My Site

Bookmarks

Posting Permissions

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