Results 1 to 4 of 4

Thread: problem capturing value with %

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    problem capturing value with %

    Hi all . i have a javascript that makes get request as shown:

    localhost/test.php?cmd=visitorRepCommand&params=visitorTyping%201&site=2020202&sessionkey=1abbcad8b561c84f7502793f1953a37f&d=1178974427466

    I wrote a php script that checks if value of params is visitorTyping%201 or visitorTyping%200.But problem is that both of my if statments fails to catch those value.could any one tell me what i am doing wrong here. i checked everything i see the values are passed corectly but it seem i am not checkinng those values corectly!!Thanks
    PHP Code:
    <?
    $cmd   = $_GET['cmd'];
    $params   = $_GET['params'];
    ....
    else if ($cmd=="visitorRepCommand" && $params=="visitorTyping%200")
    {
       echo "test1";
    }
    else if ($cmd=="visitorRepCommand" && $params=="visitorTyping%201")
    {
        echo "test2";
    }

    ?>

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: problem capturing value with %

    %20 is the URL-encoded form of a space character. PHP automatically URL-decodes HTTP parameters, so 'visitorTyping$201' comes out as 'visitorTyping 1'.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: problem capturing value with %

    Quote Originally Posted by penagate
    %20 is the URL-encoded form of a space character. PHP automatically URL-decodes HTTP parameters, so 'visitorTyping$201' comes out as 'visitorTyping 1'.
    thanks for you reply. Now i tried to do this but my query never writes to db!! could you tell me what might be wrong here?


    PHP Code:
    else if ($cmd=="visitorRepCommand" && $params=="visitorTyping 0")
    {

    $server   "localhost"// MySQL hostname
    $username "root"// MySQL username
    $password "root"// MySQL password
    $dbname   "db"// MySQL db name

    $db mysql_connect($server$username$password) or die(mysql_error());
          
    mysql_select_db($dbname) or die(mysql_error());

       
       
    $query "INSERT INTO userTypingStatus(`ID`, `cmd`, `params`, `site`, `sessionkey`) VALUES ('$ID','$cmd','$params','$site', '$sessionkey')";
            
         
    $fp fopen("userTypingStatus.txt""w");
           
    fwrite($fp$query);
           
    fclose($fp);      
           
    $result mysql_query$query );

    echo 
    "test1";

    my log file shows this but when i check db nothing is there!!

    INSERT INTO userTypingStatus(`ID`, `cmd`, `params`, `site`, `sessionkey`) VALUES ('','visitorRepCommand','visitorTyping 0','7878765', '1abbcad8b561c84f7502793f1953a37f')

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: problem capturing value with %

    add some error checking for the mysql_query() call.

    PHP Code:
    mysql_query($query) or die('error: ' mysql_error()); 
    see what the problem is. mistyped field name, bad field type or size? strict sql mode on, maybe?

Posting Permissions

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



Click Here to Expand Forum to Full Width