help with event - update db

hey folks.

not sure if this is my lousy coding or what… but I could do with a little hand in solving this.
Am trying to update the mbr table if date is today or past, the below code seems to work to an extent just that it updates regardless if true or false…
Any help would be appreciated as other forums have now reached a loss, have tried a few different combinations and have the same result each time… GRRRR

Event is onScriptInit - Form :slight_smile:


$exp_date = "{mbrDateValid}";
		$todays_date = date("Y-m-d");
		
		$today = strtotime($todays_date);
		$expiration_date = strtotime($exp_date);
		
		if ($expiration_date > $today) 
		{

			// SQL statement parameters
			$update_table  = 'mbr';      // Table name
			$update_where  = "mbrID = '{mbrID}'"; // Where clause
			$update_fields = array(   // Field list, add as many as needed
				 "mbrPaid = '0'",
				 "mbrDateValid = '0000-00-00'",
			 );
			
			// Update record
			$update_sql = 'UPDATE ' . $update_table
				. ' SET '   . implode(', ', $update_fields)
				. ' WHERE ' . $update_where;
			sc_exec_sql($update_sql);
		} 
		else 
		{
			 
		}

have the if statement working fine within a grid changing the field color, which works great, so am not sure why the same statement is failing within a form…

$exp_date = {mbrDateValid};

perhaps?

[QUOTE=aducom;15006]$exp_date = {mbrDateValid};

perhaps?[/QUOTE]

lol like I said lousy coding :slight_smile: thx

still trying to get used to the new way of doing thing :slight_smile: am getting there slowly :slight_smile:

Turn on debug mode (if you haven’t already). That should help you a lot.

regards,
Bernhard Bernsmann

[QUOTE=bartho;15031]Turn on debug mode (if you haven’t already). That should help you a lot.

regards,
Bernhard Bernsmann[/QUOTE]

cool will do thx :slight_smile:

ok where do I turn on debug mode? cant seem to find the option in settings or my scriptcase…

You can set it in every form/grid under Apllication-Settings

Other question: where did you get the {mbrDateValid} from ?

[QUOTE=Gerd Dietrich;15126]You can set it in every form/grid under Apllication-Settings

Other question: where did you get the {mbrDateValid} from ?[/QUOTE]

thx!

the {mbrDateValid} is one of my form/db fields, so local variable within the form.