Am trying to validate these variables with an if statement,but it not working,any help will do.

if($navtype == "xxxx")
	 
 {


		 $com_name = $_POST['com_name'];
		 $loc = $_POST['loc'];
		 $name_mech = $_POST['name_mech'];
		 $vtype = $_POST['vtype'];
		 $s_veration = $_POST['s_veration'];
		 $remnder_ver = $_POST['remnder_ver'];
		 $vreg = $_POST['vreg'];
		 $last_startdate = $_POST['dy']."-".$_POST['dm']."-".$_POST['dd'];		 	 
		 $mileage = $_POST['mileage'];	
		 $current_mileage = $_POST['current_mileage'];	
		 $cur_date = date("F j, Y, g:i a");
									 

if($s_veration == $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value equal to <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}

elseif($s_veration >= $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value grater than <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}

	else{exit();}
	
	   $counter=0;
	   $query = "select count(*) As counter FROM sre_log WHERE vreg = '$vreg'";  
		 $routes_result = mysql_query($query);
		 $routes_num = 0;
		 //$routes_num = mysql_numrows($routes_result);
		 $routes_num = mysql_num_rows($routes_result);
		 $i = 0;
		//$x = 1
	    while($i < $routes_num) 
			
			{
		$counter = mysql_result($routes_result,$i,"counter");
                          $i++;
			}

			
		 if ($counter == 0 )
		 
		 {
			 
		
		$sql = "insert INTO xxx 
		
		(com_name, loc, name_mech, vtype, s_veration, remnder_ver, vreg, last_startdate, mileage, current_mileage, cur_date) 
		values('$com_name','$loc','$name_mech','$vtype','$s_veration','$remnder_ver','$vreg','$last_startdate','$mileage','$current_mileage','$cur_date')";
		 }else{
			 		
$sql = "UPDATE xxx SET 

mileage_out='$mileage',mileage_in='$current_mileage',vreg='$vreg',s_veration='$s_veration',remnder_ver='$remnder_ver' WHERE vreg='$vreg'";
		 }	  
		 	mysql_query($sql);
Member Avatar for diafol

Do your POST variables actually exist?

Do your POST variables actually exist?

Yes they do, when i echo them i can see them.

Member Avatar for diafol

You don't say what happens. You exit on every condition, so the code will never progress beyond the conditional block.

Every conditional except the last one will give you a message. WHy haven't you given the 'else' an echo before exiting?

echo "sver: " . $s_veration . " and remn: " . $remnder_ver;
if($s_veration == $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value equal to <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}
 
elseif($s_veration >= $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value grater than <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}
 
	else{exit();}

These conditionals don't make sense

if($s_veration == $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value equal to <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}

elseif($s_veration >= $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value grater than <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}

In the first you are saying if $s_veration is equal $remnder_ver then it is incorrect yet your echo says that they should equal.

The second says if $s_veration is greater than or equal to $remnder_ver then it is incorrect yet your echo statement says that $s_veration SHOULD be greater than $remnder_ver.

To match your errors you need to change to

if($s_veration != $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value equal to <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}

elseif($s_veration <= $remnder_ver)
	 {
	echo" <strong>Specific Variation</strong> ought to have a value grater than <strong>Reminder Variation</strong>, please go back and alter your values";
	exit();
	}

However if the first conditional says they should be equal then your 2nd will always fail as one is not greater than the other

thank for your time simplypixie,in my application,

$remnder_ver

should never be = or grater than

$s_veration

.

$s_veration

should always be grater than this

$remnder_ver

.

tell me,is the if statement correct?

ardav wants to know what happens, it is not working, it behaves as though there is no if statement there.

In this case you just need one IF statement to check

if ($s_veration <= $remnder_ver) {
echo" <strong>Specific Variation</strong> ought to have a value grater than <strong>Reminder Variation</strong>, please go back and alter your values";
}

You shouldn't be exiting either so leave that out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.