+ Reply to Thread
Results 1 to 10 of 11
Thread: PHP/MYSQL Question.
-
24th May 2012, 10:10 PM #1NBR Resident Redneck.
- Join Date
- May 2006
- Location
- Deer stand back in the pines.
- Posts
- 5,003
- Rep Power
- 39
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:
Any ideas or work around?Code:if (isset($_POST["$checkArr[$checkCounter]"]))

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
-
25th May 2012, 01:20 AM #2NBR Super Moderator
- Join Date
- Jul 2006
- Location
- NBR Moderator HQ
- Posts
- 16,271
- Rep Power
- 89
Re: PHP/MYSQL Question.
What happens when you run this code?
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.Code:print $checkCounter print $checkArr[$checkCounter] print $_POST["$checkArr[$checkCounter]"] print isset($_POST["$checkArr[$checkCounter]"]))
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 SurroundSnow Leopard, 1.86GHz, 2GB RAM
128GB SSD, iPod Touch, 32GB iPad
-
25th May 2012, 09:01 AM #3NBR Resident Redneck.
- Join Date
- May 2006
- Location
- Deer stand back in the pines.
- Posts
- 5,003
- Rep Power
- 39
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
-
25th May 2012, 10:36 AM #4NBR Super Moderator
- Join Date
- Jul 2006
- Location
- NBR Moderator HQ
- Posts
- 16,271
- Rep Power
- 89
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 SurroundSnow Leopard, 1.86GHz, 2GB RAM
128GB SSD, iPod Touch, 32GB iPad
-
25th May 2012, 11:29 AM #5NBR Resident Redneck.
- Join Date
- May 2006
- Location
- Deer stand back in the pines.
- Posts
- 5,003
- Rep Power
- 39
Re: PHP/MYSQL Question.

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
-
29th May 2012, 11:55 AM #6NBR Resident Redneck.
- Join Date
- May 2006
- Location
- Deer stand back in the pines.
- Posts
- 5,003
- Rep Power
- 39
Re: PHP/MYSQL Question.
SOLUTION!!!!
Pre conditional:
Post conditional:Code:$checkArr[$checkCounter] = 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.Code:$stringTotal[$finalCounter] = str_replace("_", " ", $checkArr[$checkCounter]);
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
-
30th May 2012, 06:38 AM #7NBR Super Moderator
- Join Date
- Jul 2006
- Location
- NBR Moderator HQ
- Posts
- 16,271
- Rep Power
- 89
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 SurroundSnow Leopard, 1.86GHz, 2GB RAM
128GB SSD, iPod Touch, 32GB iPad
-
31st May 2012, 02:03 PM #8NBR Resident Redneck.
- Join Date
- May 2006
- Location
- Deer stand back in the pines.
- Posts
- 5,003
- Rep Power
- 39
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
-
31st May 2012, 09:21 PM #9NBR Super Moderator
- Join Date
- Jul 2006
- Location
- NBR Moderator HQ
- Posts
- 16,271
- Rep Power
- 89
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 SurroundSnow Leopard, 1.86GHz, 2GB RAM
128GB SSD, iPod Touch, 32GB iPad
-
1st June 2012, 12:40 AM #10Banned
- Join Date
- Feb 2007
- Posts
- 5,375
- Rep Power
- 0



LinkBack URL




Reply With Quote


I`m upgrading, are you? (GTX 780M...
Today, 08:40 PM in Gaming (Software and Graphics Cards)