Problem with $_POST, if isset() and mysql_fetch_assoc(): echo returns correct value, page source always returns else value?

You appear to still be checking isset() even though the question isn't whether it's set, the question is whether it's true or false. PHP munges a lot of things when you check variables as booleans but isset() on a set variable containing false will still return true Try trading if (isset($_POST'GFCheckbox')) for if ($_POST'GFCheckbox') and see what happens.

You appear to still be checking isset() even though the question isn't whether it's set, the question is whether it's true or false. PHP munges a lot of things when you check variables as booleans but isset() on a set variable containing false will still return true. Try trading if (isset($_POST'GFCheckbox')) for if ($_POST'GFCheckbox') and see what happens.

I don't think this is the answer. It works when viewing the page, he's asking what the problem is when viewing the source. You're correct in that it is a cleaner approach (it allows you to explicitly pass false), although I think most browsers will not include the parameter at all if it's unchecked.

– roe Apr 17 at 16:30 I tried this option a couple of times, but unfortunately with the same result. I was blaming $_POST, but it seems its a Google Chrome browser problem. – Mario111 Apr 17 at 16:37.

I can't see anything in that code suggesting it would output all records when submitted with the box checked. It's probably the case that when you view the page source it's not sending the POST data, so you get all the records back. If you have the Web Developer Toolbar for Firefox, you can verify this by using View Source -> View Generated Source, or alternatively with Firebug by inspecting the DOM.

Failing that, try viewing source using a different web browser.

The problem is not really all the record being output, the problem is whatever the else statement is in my if conditional loop. If I had echo "Whatever"; as my else statement, it would output whatever to my page source, regardless of the status of isset($_POST) condition. – Mario111 Apr 17 at 16:39.

Here: jfcoder.com/test/checkbox.php I have: And it's acting as you're describing you want it to. Specifically, to use a WHERE clause if the checkbox is selected on the form submit. So I don't think that it's the if statement.

If you're using MySQL, your query looks wrong. NOTE: I think most/all (see third note) relational database systems use the single quote syntax, but I'm not sure. SECOND NOTE: I'm actually looking for the documentation to see if this is true.

I've certainly always thought single quotes were required. THIRD NOTE: This is actually NOT a problem with MySQL, see When is it necessary to escape double quotes and other characters when inserting them into MySQL database? For more information.

$query = ' SELECT * FROM fdatav1 f INNER JOIN ddatav1 d USING(ID) WHERE (GFOption = "1") '; You need to use single quotes on the WHERE check, not double quotes. I would stick with single quotes for consistency, but apparently it's not required by MySQL. $query = ' SELECT * FROM fdatav1 f INNER JOIN ddatav1 d USING(ID) WHERE GFOption = \'1\' '; Or: $query = " SELECT * FROM fdatav1 f INNER JOIN ddatav1 d USING(ID) WHERE GFOption = '1' "; I believe this is probably why your results are not working as expected.

Also, IMO you should not use isset() for the if but should check for the actual status report; ie... if ($_POST'GFCheckbox' == 'on') { And I might do this a little differently (see comment): $WHERE = ""; if (isset($_POST'GFCheckbox')) { if ($WHERE == '') { $WHERE = "WHERE "; } $WHERE = "GFOption = '1'"; } // This way it's easier to add options // and edit your base query later. // For instance, in case you add a // GROUP, LIMIT or ORDER BY. If (isset($_POST'ABCCheckbox')) { if ($WHERE == '') { $WHERE = "WHERE "; } else { $WHERE = " AND "; } $WHERE = "ABCOption = 'efg'"; } $query = " SELECT * FROM fdatav1 f INNER JOIN ddatav1 d USING(ID) $WHERE.

Thanks for the reply. I originally had my comments the other way around, but switched to single outside quotes out of desperation for a solution. If I switch them back it works the same, will do so for good practice anyway.

Thank for the suggestion on the base $query! – Mario111 Apr 17 at 16:47 @Mario111 - Note I made a change, the original WHERE check was incorrect. I'm trying to determine if single quotes are required for string searches, as well.

– Jared Farrish Apr 17 at 16:49 @Mario111 - See my edit. Double quotes are allowed in MySQL after all. – Jared Farrish Apr 17 at 16:59 Thank you Jared – Mario111 Apr 17 at 17:32.

Use $_GET or $_SESSION variables The problem boiled down to Google Chrome. The issue I was having was a recognized bug in the software: code.google.com/p/chromium/issues/detail... which I believe they are fixing in future editions of Google Chrome. I have just update mine and still does not work correctly.

I switched browsers to Firefox and Explorer and they rendered everthing correctly, even the XML output I was after. Credit for this solution goes out to Roe for pointing out the potenital browser problem. According to other posts using $_GET in stead of $_POST should work fine.

$_SESSION variables should also do the trick.

I eventually ended up migrating to an AJAX solution, which made use of the POST method and it worked fine with all browsers. – Mario111 Apr 25 at 18:55.

It does seem that I am homing in on the problem. I then have a PHP function that checks if GFCheckbox is selected. If it is a certain string is passed to the $query value.

If it isn't a different string is passed to the $query value. Here is the PHP function. When I select the checkbox, all the echo statements work perfectly and displays on screen all the records where GFOption = "1".

But when I view the page source ALL the records are echoed there. This is however specific to whatever I have in the else statement of the if condition. If the checkbox is checked or unchecked, whatever I have in the else statement executes and if there is output it gets printed to the page source.

The statements work exactly the way they should, and no weird page source printing happens. I get the correct boolean values depending on if GFCheckbox is checked or not. As you can see I am running in circles with this and would really appreciate any help.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions