Jump to content

Struggling with logic


Guest elthomo

Recommended Posts

Guest elthomo

I have a situation where I need to check if a certain radio button(returns the value "werkgever") has been chosen then the user must fill in a text box which returns the var "$werkgever"  also I need to check that the same radio buttons are not left blank.

What I have tried to do with the $error2 var is if they fill in the werkgever text box it removes 1 from the error2 count(I want it to be ok if they fill that in and they did not choose the werkgever radio button)  If they choose the werkgever radio button it should add 1 to the error2 count.  So unless they only choose the werkgever radio button the value should be 0 or -1. Sadly I think I may have flawed logic. Any suggestions on making my code work  or maybe I should be doing this in a completely different way? 

 

Here is the part of the code thats relevant.

<?php
$error=0; // check up if radio buttons selected
$error2=0; // check if  werkgever is selected from broninkomsten then werkgever field must be filled in

	if (!valid_werkgever($werkgever)){
//		$eerror = "<font color=\"#FF0000\" size=2>- U heeft geen geldig straatnaam ingevuld.</font><br>";
	$error--; // $error=$error-1;
	}
        if ($_POST['broninkomsten'] == ' '){
                $aerror = "<font color=\"#FF0000\" size=2>- U heeft geen geldig broninkomsten ingevuld.</font><br>";
	$error++; // $error=$error+1;
	}
if ($_POST['broninkomsten'] == 'Werkgever'){
	$error2++;        	
	}
if(($error == 0)&&($error2 <=0))  
{
mysql_query("INSERT INTO `machtiging` (dossiernummer, betalenbedrag, ingangvan, werkgever, betalenWM, broninkomsten) VALUES ('$dossiernummer', '$betalenbedrag', '$ingangvan', '$werkgever', '$betalenWM', '$broninkomsten')");

header("Location: page1.php?achternaam=$achternaam&dossiernummer=$dossiernummer");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/97210-struggling-with-logic/
Share on other sites

Guest elthomo

Ok solved it myself in the end. I was bad logic. It wasn't possible to do what i wanted with just two var. So i used three and all is good. Heres the code incase anyone is interested.

 

if((($error == 0)&&($error2 ==1)&&($error3 ==0)) || (($error == 0)&&($error2 ==0)))

 

 

Link to comment
https://forums.phpfreaks.com/topic/97210-struggling-with-logic/#findComment-497473
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.