www.webdeveloper.com
Results 1 to 7 of 7

Thread: preg_match problem need solution?

Threaded View

  1. #1
    Join Date
    Nov 2013
    Posts
    4

    preg_match problem need solution?

    I have problem with my preg_match function it seems it always returns true no matter what's in the input form? it suppose to just return true when the value has junkies in it.

    this is part of the code, the echo in thisCheckerNum always display 1, even when $_POST['number2'] has nothing in it... , and because of that it will always go to "die("Error: passwordOld contains invalid characters!");", I need to know why..


    PHP Code:
    function thisCheckerNum($str)
    {
        
    $var preg_match('/^[a-zA-Z0-9]*$/'$str);
        echo 
    $var;
        return 
    $var;
    }

        if (isset(
    $_POST['number1']) && isset($_POST['number2'])) {
            
    $passwordOld $_POST['number2'];
            
    $passwordOld2 $_POST['number3'];
            
    $passwordNew $_POST['number4'];
            
    $passwordNew2 $_POST['number5'];
            
    $sql "SELECT * FROM users WHERE email='$email' AND password='$passwordOld'";
            
    $query mysql_query($sql);

            
    /* filter vals*/
            
    $passwordOld mysql_real_escape_string(html_entity_decode(htmlentities($passwordOld)));
            
    $passwordOld2 mysql_real_escape_string(html_entity_decode(htmlentities($passwordOld2)));
            
    $passwordNew mysql_real_escape_string(html_entity_decode(htmlentities($passwordNew)));
            
    $passwordNew2 mysql_real_escape_string(html_entity_decode(htmlentities($passwordNew2)));
            
    /*
            This counts how many records match our query
            */
            
    echo $email."<br \>".$passwordOld."<br \>".$passwordOld2."<br \>".$passwordNew."<br \>".$passwordNew2."<br \>";
            
    //Die if account contains non-alphanumeric characters
            
    if(thisCheckerNum($passwordOld) == 1)
            {
              die(
    "Error: passwordOld contains invalid characters!");
            } 
    Last edited by NogDog; 11-12-2013 at 09:01 PM. Reason: changed I tags to PHP tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles