PC Nerd Posted February 6, 2007 Share Posted February 6, 2007 hey guys i have code similar to this: if($Research['1_00'] != True) { ###DISPLAY ERROR MESSAGE } else { ### Do stuf } now my problem is that i have checked my database and the $Research['1_00'] value IS TRUE ( 1 in phpmyadmin ) but this code doesnt work, it raises the error now is this a problem with my testing of the boolean value, or is it with the database THANKX Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 1 in phpmyadmin? what do you mean by that. and instead of writing it out like this you can write it like this: if(!$Research['1_00']){ Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 well just like you have TRue and False on on and off, right and wrong, youve got 0 nd 1, (fals and true respecftively) if i use if(!$Research['1_00']){} does that test whether it exists, or whether it is true??? thankx Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 if you use 1 and 0 then thats not really checking if it is true or false, i dont think. you'd have to check whether it was 1 or 0. and just so you no, if you place a ! in front of a variable you are checking if it is false. thats assuming the variable is a boolean (true or false). if you want to check if it is true just use if($variable){ and it would check if it is set to true. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 6, 2007 Share Posted February 6, 2007 if you're saying how to avoid the auto typcasting? use !== and === $test = "true"; if($test === true){ echo 'Test'; } this wouldn't output anything because $test is a string, the same rules apply to !== $test = false; if($test !== "false"){ echo 'Test'; } this will output "test" because $test is bool and you're seeing if it's "false" (a string) sorry if I missed your question, I'm tired Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 correct me if i'm wrong someone, but can the true and false contain capitals. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 ok this is probably a question for poeple who use phpmyadmin. when you have a boolean field ( implemented as intyint(11) i think) )and the datase says "1" (without the quotes) does it mean that the value is TRUE. or is the 1, showing you that the field is a text or other, and the 1 is a string or integer??? i tried the if(!$Research['1_00']){} and it still raisees the error. ,my full code around this probmel part is....: <? ### connect to the database and retreive research information require('inc_files/Database_link.inc'); $Research_SQL = "SELECT * FROM General_Stats WHERE User_ID = ".$_COOKIE['User_ID'];#User_ID, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21, 1_22, 1_23 FROM Ice_Ages WHERE User_Name = ".$_COOKIE['User_ID']; $Research_Query = mysqli_query($DB_Server, $Research_SQL) or die("ERROR 5 There was an error in retreiving your research status from the database. Please try again later, and if the problem persists please write down the error number, and email us with this Number"); $Research = mysqli_fetch_array($Research_Query) or die("ERROR 6 There was an error while using your research status. Please try again later."); ### Test Research Data to determine the next option of reasearch if (!$Research['1_00']) { die ("ERROR 7 "); } if ($Research['1_01'] == "True") { if($Research['1_02'] == "True") { if($Research['1_10'] != "True") {.......... ok, ignore the if's after the first tesgint eh ['1_00'] i need to shcnge them to work. but its the first if thats cauaseing me trouble thankx Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 if they are either 1 or 0 you have would have to check whether they are 1 or 0. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 if($Research['1_00'] != 1) doesnt work anything else i should try to change??? thanx Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 what is $Research['1_00'] value? is it 1, 0, true or false? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 in the database it is true, and always will be from the moment you sign up, but its checking it to see if its not, just in case of an error Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 alright, well you should be able to just go like this: if(!$Research['1_00']){ but it must be 'true' not 'True' Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 so where you go 'ture' not 'True', is that the value in the database???? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 yes, if it is set to true in the database then the value MUST be true. no caps, same with false. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 its still not working, no matter the data type, or the value ive tried to make it text, and have it case sensitive to "True", boolean, int... i cant seem to fix it thankx 4 ur help thoug, is there anything else??? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 alright. this is what i do. if the value is false i set it to 0 in my database. so the field type is tinyint. then when checking the value i'd go: if($Research['1_00'] == 0){ that would check if it is false or no, which is another thing i use 0 and 1 for. 0 = no, 1 = yes Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 ok,that worked thanx sooooooo much Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 6, 2007 Author Share Posted February 6, 2007 FALSE ALRAM soz guys its giving me output, although its wrong output. whats happening in some cases is its the inverse operation if !=1 give the output as !=0 but other times, it just defults back to the first if() wthich isnt very good. my database if a bool, but when i manually enter data into the fieldsd as the record im veiwing....... i type true into the boolean fieild and it ends up as 0...... and the same as if i went 1 instead of true. although is sometimes worked if the field was text type with true as the value.... its really patchy, not the same every time.... can you help me Now if i change from == 1 TO !=1, it gives the correct output.... if ($Research['1_00'] == 0) { } else { die ("ERROR 7 "); } if ($Research['1_01'] == 1) { if($Research['1_02'] == 1) { if($Research['1_10'] != 1) { $Res_avail['1_10'] = "True"; } if($Research['1_03'] == 1) { if($Research['1_05'] == "True") { if($Research['1_06'] == "True") { if($Research_['1_07'] != "True") { $Res_Avail = "True"; } if($Research['1_08'] != "True") { $Res_Avail = "True"; } } if($Research['1_09'] != "True") { $Res_Avail['1_09'] = "True"; } } else { $Res_Avail['1_05'] = "True"; } $Res_Avail['1_04'] = "True"; } else { $Res_Avail['1_03'] = "True"; } } else { $Res_Avail['1_02'] = "True"; } } else { $Res_Avail['1_01'] = "True"; } this is the first section of code..... the database ass it stands is a boolean type, and with the values of 1 for 1 - 5, but 6 - onwards ( $Research array) are all text and empty ( NULL) so they should equate to being false ( empty ( if($Research['1_06'] != 1) {will turn true, becauase its NULL in the Database})) thankz Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 wow... now i am even more confused then i was at the start. sorry, but you've really lost me. the only thing i can say is change your field types to tinyint and that 0 is the same as false and 1 is the same as true. Quote Link to comment 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.