Quantcast PHP/MYSQL Question.

+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    NBR Resident Redneck.
    Join Date
    May 2006
    Location
    Deer stand back in the pines.
    Posts
    5,003
    Rep Power
    39

    Default PHP/MYSQL Question.

    Ok well Im working on a PHP and mysql application and I have hit a wall...hard. I have tried searching but its a very specific question and while Im trying to learn as I go I may have forgotten something along the way.

    Basically I query the database, set the output to an array, and filter depending on whats checked. The application works for all check boxes except those with a space in their name. Now I thought I remember that $_POST might not handle spaces in form attributes which would explain my issue, but also means that I cannot name DB entries with spaces (DEFINITELY needed).

    Here is my conditional:

    Code:
    if (isset($_POST["$checkArr[$checkCounter]"]))
    Any ideas or work around?

    Main rig: Dell precision m4600 - 2860QM, firepro 5950, 16GB 1600mhz RAM 9-9-9-28, WLED FDH+, Intel 520 240GB mSata OS, Seagate hybrid 750GB storage.
    Home Web/FTP/SSH Server: Dell precision m4400 Debian squeeze

  2. #2
    NBR Super Moderator
    Join Date
    Jul 2006
    Location
    NBR Moderator HQ
    Posts
    16,271
    Rep Power
    89

    Default Re: PHP/MYSQL Question.

    What happens when you run this code?

    Code:
    print $checkCounter
    print $checkArr[$checkCounter]
    print $_POST["$checkArr[$checkCounter]"]
    print isset($_POST["$checkArr[$checkCounter]"]))
    I wouldn't be surprised if $_POST didn't support spaces, either. I seem to remember having that sort of issue a few years ago when I was working on some PHP websites.

    I take it the name is the $_POST variable? You might want to try adding a unique auto-increment field to the database and reference than rather than a name. If you need the name again just query the database with the unique numeric ID.
    Desktop   13.3" Macbook Air
    W7 Ultimate, Core i7 2600k, Crucial M4 128GB SSD   
    8GB RAM, GTX 680, 3x Dell U2412M Surround
       Snow Leopard, 1.86GHz, 2GB RAM
       128GB SSD, iPod Touch, 32GB iPad

  3. #3
    NBR Resident Redneck.
    Join Date
    May 2006
    Location
    Deer stand back in the pines.
    Posts
    5,003
    Rep Power
    39

    Default Re: PHP/MYSQL Question.

    The first two print fine outside of the conditional I set (all array elements and the count as expected). The last two break the page. The array is fine, rather its the $_POST with spaces I think. As for using something else, I cannot. The check boxes are to choose and select database entries as a filter (e.g. project A, project B, etc).

    Main rig: Dell precision m4600 - 2860QM, firepro 5950, 16GB 1600mhz RAM 9-9-9-28, WLED FDH+, Intel 520 240GB mSata OS, Seagate hybrid 750GB storage.
    Home Web/FTP/SSH Server: Dell precision m4400 Debian squeeze

  4. #4
    NBR Super Moderator
    Join Date
    Jul 2006
    Location
    NBR Moderator HQ
    Posts
    16,271
    Rep Power
    89

    Default Re: PHP/MYSQL Question.

    Encode the string as HTML and put that into the database (that should involve the use of non-breaking spaces or HTML encoded spaces). Pretty sure those characters are "& nbsp ;" (remove spaces) and "%20". Make sure you sanitize your inputs if you're going to do that though (really applies regardless). Does that work?
    Desktop   13.3" Macbook Air
    W7 Ultimate, Core i7 2600k, Crucial M4 128GB SSD   
    8GB RAM, GTX 680, 3x Dell U2412M Surround
       Snow Leopard, 1.86GHz, 2GB RAM
       128GB SSD, iPod Touch, 32GB iPad

  5. #5
    NBR Resident Redneck.
    Join Date
    May 2006
    Location
    Deer stand back in the pines.
    Posts
    5,003
    Rep Power
    39

    Default Re: PHP/MYSQL Question.

    Quote Originally Posted by Greg View Post
    Encode the string as HTML and put that into the database (that should involve the use of non-breaking spaces or HTML encoded spaces). Pretty sure those characters are "& nbsp ;" (remove spaces) and "%20". Make sure you sanitize your inputs if you're going to do that though (really applies regardless). Does that work?
    Ill look into it when the wife gets home. Right now Im on baby duty. Thanks for the tips!

    Main rig: Dell precision m4600 - 2860QM, firepro 5950, 16GB 1600mhz RAM 9-9-9-28, WLED FDH+, Intel 520 240GB mSata OS, Seagate hybrid 750GB storage.
    Home Web/FTP/SSH Server: Dell precision m4400 Debian squeeze

  6. #6
    NBR Resident Redneck.
    Join Date
    May 2006
    Location
    Deer stand back in the pines.
    Posts
    5,003
    Rep Power
    39

    Default Re: PHP/MYSQL Question.

    SOLUTION!!!!

    Pre conditional:
    Code:
    $checkArr[$checkCounter] = str_replace(" ", "_", $checkArr[$checkCounter]);
    Post conditional:
    Code:
    $stringTotal[$finalCounter] = str_replace("_", " ", $checkArr[$checkCounter]);
    Talked to my brother in law thinking he wasnt dabbling in PHP and he mentioned that POST converts spaces in its array to "_" and 2 lines later I had my problem solved.

    Main rig: Dell precision m4600 - 2860QM, firepro 5950, 16GB 1600mhz RAM 9-9-9-28, WLED FDH+, Intel 520 240GB mSata OS, Seagate hybrid 750GB storage.
    Home Web/FTP/SSH Server: Dell precision m4400 Debian squeeze

  7. #7
    NBR Super Moderator
    Join Date
    Jul 2006
    Location
    NBR Moderator HQ
    Posts
    16,271
    Rep Power
    89

    Default Re: PHP/MYSQL Question.

    Nice find. That had better be a documented feature with POST or heads might roll in the future if/when that behavior breaks. Don't get me started with relying on undocumented features for functionality .
    Desktop   13.3" Macbook Air
    W7 Ultimate, Core i7 2600k, Crucial M4 128GB SSD   
    8GB RAM, GTX 680, 3x Dell U2412M Surround
       Snow Leopard, 1.86GHz, 2GB RAM
       128GB SSD, iPod Touch, 32GB iPad

  8. #8
    NBR Resident Redneck.
    Join Date
    May 2006
    Location
    Deer stand back in the pines.
    Posts
    5,003
    Rep Power
    39

    Default Re: PHP/MYSQL Question.

    Yeah that will become yet another bug Ill spend hours trying to figure out. Honestly I looked at PHP.net and I didnt see anything about how they convert spaces in the array or else a str_replace would have been implemented loooooong ago. All in all its fixed....for now so Im happy.

    Main rig: Dell precision m4600 - 2860QM, firepro 5950, 16GB 1600mhz RAM 9-9-9-28, WLED FDH+, Intel 520 240GB mSata OS, Seagate hybrid 750GB storage.
    Home Web/FTP/SSH Server: Dell precision m4400 Debian squeeze

  9. #9
    NBR Super Moderator
    Join Date
    Jul 2006
    Location
    NBR Moderator HQ
    Posts
    16,271
    Rep Power
    89

    Default Re: PHP/MYSQL Question.

    I'd still document that in the comments. One of those bugs you'll spend another few hours on if you ever have to revisit it and forget.
    Desktop   13.3" Macbook Air
    W7 Ultimate, Core i7 2600k, Crucial M4 128GB SSD   
    8GB RAM, GTX 680, 3x Dell U2412M Surround
       Snow Leopard, 1.86GHz, 2GB RAM
       128GB SSD, iPod Touch, 32GB iPad

  10. #10
    Banned
    Join Date
    Feb 2007
    Posts
    5,375
    Rep Power
    0

    Default Re: PHP/MYSQL Question.

    Quote Originally Posted by Greg View Post
    I'd still document that in the comments. One of those bugs you'll spend another few hours on if you ever have to revisit it and forget.
    The joys of debugging code. I don't miss it.

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -4. The time now is 10:58 PM.
Powered by vBulletin® Version 4.2.0
Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.
SEO by vBSEO 3.6.0