jason1987 Posted October 17, 2007 Share Posted October 17, 2007 My if statement is not working the code inside is being ran everytime even when it dont meet the conditions, when i test my code with echo on the update statement its not liking lines brings up an undefined index notice for these lines $simparent=$HTTP_POST_VARS['simparentid']; $equtype=$HTTP_POST_VARS['equtypeid']; $simparent=$HTTP_POST_VARS['simparentid']; $equtype=$HTTP_POST_VARS['equtypeid']; if ($simparent == !'Null') { if($equtype == '8' || '8') { $simins = "UPDATE itsiminfo SET simparentid=NULL WHERE itsiminfo.equid='$equid'"; $resultsimins = mysql_query($simins); // Removes link between sim card and mobile/3G - only from SIM though not via mobile or 3G } if($equtype == '7' || '4') { $simins2 = "UPDATE itsiminfo SET simparentid=NULL WHERE simparentid='$equid'"; $resultsimins2 = mysql_query($simins2); //Removes link between Mobile/3g and sim - from through mobile or 3g } } Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/ Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 you may want if ($simparent != 'Null') Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371581 Share on other sites More sharing options...
jason1987 Posted October 17, 2007 Author Share Posted October 17, 2007 I Have changed this, but still dont appear to be working correctly ??? ??? $simparent=$HTTP_POST_VARS['simparentid']; $equtype=$HTTP_POST_VARS['equtypeid']; if ($simparent != 'Null') { if($equtype == '8' || '8') { $simins = "UPDATE itsiminfo SET simparentid=NULL WHERE itsiminfo.equid='$equid'"; $resultsimins = mysql_query($simins); // Removes link between sim card and mobile/3G - only from SIM though not via mobile or 3G } if($equtype == '7' || '4') { $simins2 = "UPDATE itsiminfo SET simparentid=NULL WHERE simparentid='$equid'"; $resultsimins2 = mysql_query($simins2); //Removes link between Mobile/3g and sim - from through mobile or 3g } } Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371615 Share on other sites More sharing options...
kenrbnsn Posted October 17, 2007 Share Posted October 17, 2007 Use "$_POST", not "$HTTP_POST_VARS". Ken Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371616 Share on other sites More sharing options...
jason1987 Posted October 17, 2007 Author Share Posted October 17, 2007 Changing that didnt affect anything ??? Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371622 Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 if($equtype == '8' || '8') you want: if($equtype == '8') because '8' will always be true. same with the other one. if($equtype == '7' || '4') should be if($equtype == '7' || $equtype == '4') because '4' will always be true Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371637 Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 hm, also, my mistake, this will only affect whether the value is the literal string 'Null' if ($simparent != 'Null') if you want to see whether there is a value, i would use if (!is_set($somevalue)) or if (trim($somevalue) == "") Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371641 Share on other sites More sharing options...
kenrbnsn Posted October 17, 2007 Share Posted October 17, 2007 Try this instead of your code: <?php $simparent=$_POST['simparentid']; $equtype=$_POST['equtypeid']; if (strlen($_POST['simparentid']) > 0) { switch ($_POST['equtype']) { case '8': $q = "UPDATE itsiminfo SET simparentid=NULL WHERE itsiminfo.equid='$equid'"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); case '7': case '4': $q = "UPDATE itsiminfo SET simparentid=NULL WHERE simparentid='$equid'"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); default: echo 'equtype is not 8, 7, or 4 but :' . $_POST['equtype'] . '<br>'; } } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371649 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.