SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Sep 2005
    Location
    England
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed with query!

    Hi there

    I have a strange problem that for the life of me I cannot work out!

    First I pass via the url a variable $standardName = 'P&G 1469'. Obviously before it is passed via the URL it needs to be encoded so I urlencode($standardName).

    This variable is passed to a second page which unencodes the variable using urldecode($standardName)

    If I do the following:
    PHP Code:
    "SELECT * FROM standard WHERE standardname = '$standardName'" ;
        
    $result pg_query($sql);    
        
    $totalrows pg_num_rows($result); 
    Zero rows are found, yet if I echo the same sql statement to the screen and copy and paste that into my 'Terminal' window it returns the desired row!

    What makes it more weird is that if I hard code the sql query to be:
    PHP Code:
    SELECT FROM standard WHERE standardname 'P&G 1469';    $result pg_query($sql);    
        
    $totalrows pg_num_rows($result); 
    Then 1 row is returned!!.

    It must be something to do with urlencoding() and urldecodeing() the '&'...

    Please help, this is really getting to me....

    I hope you all managed to follow that
    Kind Regards

  2. #2
    SitePoint Enthusiast zlaajaa's Avatar
    Join Date
    Feb 2005
    Location
    home?
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, first try to do var dump to see what is in $standardName:
    PHP Code:
    var_dump($standardName); 
    and about query:
    PHP Code:
    $sql "SELECT * FROM standard WHERE standardnam = '".$standardName."'"

  3. #3
    SitePoint Member
    Join Date
    Sep 2005
    Location
    England
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi zlaajaa

    Thanks for your help.

    I did:
    PHP Code:
    var_dump($standardName); 
    It produced this:
    PHP Code:
     string(31"P&G 0001 Yellow Sphere 100%" 
    What should I be looking for?

    Many thanks
    Vittel

  4. #4
    SitePoint Zealot metacube's Avatar
    Join Date
    Jun 2005
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    'P&G 0001 Yellow Sphere 100%' is 27 characters (quick count, may be wrong). Can you look in the source of the page? It may be showing a html entity for one of the characters... (e.g. it's showing & but actually echoing & )

  5. #5
    SitePoint Member
    Join Date
    Sep 2005
    Location
    England
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey metacube!

    That's it!..

    The source code was:
    Code:
    string(31) "P&G 0001 Yellow Sphere 100%"
    Thank you very much.

    So what is the best way of making it show '&' instead of '&'?

    Thanks again
    Vittel

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    htmlentities() or htmlspecialchars()
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Member
    Join Date
    Sep 2005
    Location
    England
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi spikeZ

    Thanks for advice. I have tried it but am not sure where I am meant to apply it.

    Do I do htmlentities() / htmlspecialchars() before of after I pass the variable $standardName via the URL?

    Thanks
    Vittel

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    onto it!
    So that after it has come through the url but before it is used in the query
    htmlentites($standardName);
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Member
    Join Date
    Sep 2005
    Location
    England
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's what I thought, I tried that but it didn't work.

    This is what I did:
    PHP Code:
    var_dump($standardName);
    htmlentities($standardName);
    $sql =     "SELECT * FROM standard WHERE standardname = '".$standardName."'"
    This is the HTML source produced:
    HTML Code:
    string(31) "P&G 0004 Orange Sphere 100%"
    sql = SELECT * FROM standard WHERE standardname = 'P&G 0004 Orange Sphere 100%'
    Any suggestions what I am doing wrong?

    Thanks

  10. #10
    SitePoint Member
    Join Date
    Sep 2005
    Location
    England
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok got it now!

    Thanks for helping me in the right direction.

    I used:

    PHP Code:
    $standardName html_entity_decode($standardName); 
    Thanks for everybodies help!
    Vittel

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    that'll be it then!
    Glad you got it sorted Vittel

    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Zealot metacube's Avatar
    Join Date
    Jun 2005
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it's good it works now.

    Always remember that what a browser displays isn't necessarily the same as the code that's being echoed


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
  •