Jump to content

IF statement help


jason1987

Recommended Posts

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
}
}

Link to comment
https://forums.phpfreaks.com/topic/73656-if-statement-help/
Share on other sites

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
}
}

Link to comment
https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371615
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/73656-if-statement-help/#findComment-371649
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.