pioneerx01 Posted March 4, 2011 Share Posted March 4, 2011 What is the difference between writing if ($_POST['something'] == "" ) echo "that"; and if ($_POST[something] == "" ) echo "that"; and would it have any effects? Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/ Share on other sites More sharing options...
Muddy_Funster Posted March 4, 2011 Share Posted March 4, 2011 try it and see Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182835 Share on other sites More sharing options...
pioneerx01 Posted March 4, 2011 Author Share Posted March 4, 2011 I did, and the both seem to work. Just I am having some issues that should not be happening because I have a code in place to prevent it. But the difference is...see above I just want to know that one browser does not see it differently (or ignore it) than other.. Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182837 Share on other sites More sharing options...
cunoodle2 Posted March 4, 2011 Share Posted March 4, 2011 I just want to know that one browser does not see it differently (or ignore it) than other.. PHP is SERVER side and all it does is create files for the browser to then interpret. The actual php functions will NOT change from browser to browser. However the output created by php could be interpreted different from one browser to another. Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182838 Share on other sites More sharing options...
KevinM1 Posted March 4, 2011 Share Posted March 4, 2011 The second one shouldn't be working as the keys to the $_POST array are strings. Without the single quotes, PHP will treat it like a constant. Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182843 Share on other sites More sharing options...
Pikachu2000 Posted March 4, 2011 Share Posted March 4, 2011 What is the difference between writing if ($_POST['something'] == "" ) echo "that"; and if ($_POST[something] == "" ) echo "that"; and would it have any effects? PHP will throw a warning and waste time as it first tries to interpret the unquoted array index as a constant, then finally decides that since no constant by that name exists it should be treated as a string. If you had error reporting on, you'd see that. Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182848 Share on other sites More sharing options...
448191 Posted March 4, 2011 Share Posted March 4, 2011 PHP treats undefined constants as strings. Up your error reporting level and you'll see that the second example is actually horribly wrong. Another example is: echo FOO . PHP_EOL; const('FOO', 'bar'); echo FOO . PHP_EOL; Will output: FOO bar Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182850 Share on other sites More sharing options...
pioneerx01 Posted March 4, 2011 Author Share Posted March 4, 2011 Ok so, correct way is to use if ($_POST['something'] == "" ) echo "that"; Thnaks Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182852 Share on other sites More sharing options...
PFMaBiSmAd Posted March 4, 2011 Share Posted March 4, 2011 Here's a monkey wrench thrown in - I'm going to guess that in your actual code you are having a problem with, someone used a defined constant for the array index name and in the case where you put the quotes around it, your code actually stopped working? A more reasonable answer: As already suggested, you should be developing and debugging your code on a system with error_reporting set to E_ALL (or to a -1) and display_errors set to ON so that you would be seeing all the errors that php detects. Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182857 Share on other sites More sharing options...
pioneerx01 Posted March 4, 2011 Author Share Posted March 4, 2011 The code works fine 98% of the time. It is just that 1 out of 50 something happens and I am not sure why: I have a project registration form where you have to enter first students name. Than you have an option "is there a second student? Yes - No" No is selected by default. If they click yes fields are un-disabled and second student info can be entered. Same thing for third. If they select yes and enter no student, or enter no first student, or if their java scrip is off and they keep no and enter student name, PHP will tell them to fix it. I believe I am covered on that well. In post processing I have a code that looks and see if second/third name are blank and if they are it assigns value of 'nostudent' to those appropriate blank fields. Most of the submissions got processed OK, but I had one second and third name in the database that were blank, but 'nostudent' was not entered there. (and selections for both second/third student were NO) So I assigned default value in database for second and third names to be 'nostudent'. Again most for the submissions went fine, and that again I got one where second and third name in the database were blank, but 'nostudent' was not entered there (and selections for both second/third student were NO). So, I added extra feature to code and told it if second/third names are blank or if the selection for second/third are NO, assign value of 'nostudent' to those appropriate blank fields. Keep in mind that if they select yes and enter nothing or vice versa they get error. Again few went fine and I got one this morning. Hence my original question P.S. As I was typing this I got in 12 registrations, all fine. Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182865 Share on other sites More sharing options...
Muddy_Funster Posted March 4, 2011 Share Posted March 4, 2011 that the default value on the DB was over written meens that something is happening that is assigning a value to these second and third students. Have you checked what happens if you choose yes to additional students, fill in some info, and then change it back to no again for the final submition? Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182877 Share on other sites More sharing options...
pioneerx01 Posted March 4, 2011 Author Share Posted March 4, 2011 Works fine (well for me). I have even entered three spaces for third and and I do got 'nostudent' in DB. And still if you select no for second/third student (even if you put a name in with javascript off) PHP is instructed to give you an error. On top of that it is also instructed at the end to put 'nostudent' in the fields if NO is selected for second/third student. Oh, and there is no other thing that has write privileges to this table, so that form is the only one. Quote Link to comment https://forums.phpfreaks.com/topic/229585-what-is-the-difference-bertween-writing-and/#findComment-1182889 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.