Jump to content

problems with preag_match function

- - - - -

  • Please log in to reply
5 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi. Once again i have to bother you with "worked in wamp, but does not work in host" problem. Let's say i type "lamato" in username field of form. Then why the code below executes function printErrorMessage("Username must contain only letters and numbers and be from 6 to 18 symbols length");
    if (!isset($_POST['userName']))
        printErrorMessage("Username is not filled in");
    if (strlen(trim($_POST['userName'])) == 0)
        printErrorMessage("Username is not filled in");
    //echo $_POST['userName'];    
    $usernamePattern = "/^[a-zA-Z0-9]{6,18}$/";
    if (!preg_match($usernamePattern, $username))
        printErrorMessage("Username must contain only letters and numbers and be from 6 to 18 symbols length");
It's really frustrating that so many things that worked on wamp doesn't work in real host. I programmed my web two weeks ago and i still cannot make it work properly. Sorry for vaining, but i need help.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Let's start with something simple: are you using the same version of PHP, MySQL, and Apache on both machines? If not, you could have all manner of problems. In addition, if there are different default encodings on the two systems, things can get REALLY strange.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
in wamp: Php 5.3.5, Mysql 5.5.8 In host: 5.3.6 php, mysql 5.5.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I'd check and see if you're getting leading/trailing spaces on the username for your server.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Think: Are you checking input when an error occurs? You should be double checking all input prior to calling preg_match, a vague error is likely not the issue, it is a result of a previous issue.

Try to var_dump($username) directly before calling preg_match and you will see why it fails.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Thanks for help. Had a silly mistake. Problem solved




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users