<![CDATA[ 1.0.12 - Updating MySQL database using if(....) conditional - MODX Community Forums]]> https://forums.modx.com/thread/?thread=91805 <![CDATA[Re: 1.0.12 - Updating MySQL database using if(....) conditional]]> https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501785
I can't see all code being used in your script but...

Modify the code to this

// ******** UPDATE SESSION 1 PLACES **********
 
if (isset($RSAchecked) && ($RSAchecked === 1)) {
    // update_places1($id1, $seats);
    print "RSAchecked variable is set and id1 equals ". $id1 " | seats equals ". $seats;
}
 
// ******** UPDATE SESSION 2 PLACES **********
  
if (isset($RSGchecked) && ($RSGchecked === 1))  {   
    //update_places2($id2, $seats);
    print "RSGchecked variable is set and id2 equals ". $id2 " | seats equals ". $seats;
}


if that works and you see the values being correct then try run

// ******** UPDATE SESSION 1 PLACES **********
 
if (isset($RSAchecked) && ($RSAchecked === 1)) {
    update_places1($id1, $seats);
}
 
// ******** UPDATE SESSION 2 PLACES **********
  
if (isset($RSGchecked) && ($RSGchecked === 1))  {   
    update_places2($id2, $seats);
}



When I create a CRUD form. I write 3 functions: Create, Update and Delete. You are just updating existing fields.]]>
mrhaw Jun 30, 2014, 02:28 AM https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501785
<![CDATA[Re: 1.0.12 - Updating MySQL database using if(....) conditional]]> https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501769 $update_seats1 = part actually be $update_places1 ...??? and there appears to be an extra }.)

I would be grateful if you would advise if I understand your logic correctly -

UPDATE SESSION 1 PLACES FUNCTION - If RSAchecked is set and has the value of 1 then it will set the function $update_seats1 so that it exists.
Then the
if (!function_exists('update_places1'))
code block will return FALSE if not set and do nothing, otherwise if it is set then the MySQL statement will run?
When you say, 'This is the first thing I would do...' , is there more, like a return or something I am missing?

The entire script completes with no errors and emails are sent but the database is not updated.
I am still on a learning curve with this so I appreciate your patience and help.]]>
Twobears Jun 29, 2014, 09:09 PM https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501769
<![CDATA[Re: 1.0.12 - Updating MySQL database using if(....) conditional]]> https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501601
require_once('../manager/includes/config.inc.php');
require_once('../manager/includes/document.parser.class.inc.php');
$modx = new DocumentParser;

if (!function_exists('update_places1')) {
    function update_places1($id1, $seats) {        
        global $modx;       
        $table = "`prefix_modx`.`xtra_session`";        
        $update_seats1 = '`places` -' .$seats;      
        $result = $modx->db->update( '`places` = ' . $update_seats1, $table, '`id` = ' . intval($id1, 10) . ' AND `places` >= ' . $seats );        
        return $result; // Returns 'true' on success, 'false' on failure.
      }
    }
}
if (!function_exists('update_places2')) {
    function update_places2($id2, $seats) {        
        global $modx;       
        $table = "`prefix_modx`.`xtra_session`";        
        $update_seats2 = '`places` -' .$seats;      
        $result = $modx->db->update( '`places` = ' . $update_seats2, $table, '`id` = ' . intval($id2, 10) . ' AND `places` >= ' . $seats );        
        return $result; // Returns 'true' on success, 'false' on failure.
      }
    }
}

// ******** UPDATE SESSION 1 PLACES **********

if (isset($RSAchecked) && ($RSAchecked === 1)) {
    $update_seats1 = update_places1($id1, $seats);
}

// ******** UPDATE SESSION 2 PLACES **********
 
if (isset($RSGchecked) && ($RSGchecked === 1))  {   
    $update_seats2 = update_places2($id2, $seats);
}  
]]>
mrhaw Jun 27, 2014, 01:34 AM https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501601
<![CDATA[1.0.12 - Updating MySQL database using if(....) conditional]]> https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501597 The original MySQL update statement below works fine without the if (....) part around it, but with the if (....), the database doesn't update. However, the rest of the processing script continues to complete (ie; sends emails etc;)
Any guidance on my syntax would be greatly received.

require_once('../manager/includes/config.inc.php');
require_once('../manager/includes/document.parser.class.inc.php');
$modx = new DocumentParser;

// ******** UPDATE SESSION 1 PLACES **********

if (isset($RSAchecked) && ($RSAchecked === 1)) {

$update_seats1 = update_places1($id1, $seats);	
function update_places1($id1, $seats) {        
	global $modx;		
	$table = "`prefix_modx`.`xtra_session`";	    
	$update_seats1 = '`places` -' .$seats;		
	$result = $modx->db->update( '`places` = ' . $update_seats1, $table, '`id` = ' . intval($id1, 10) . ' AND `places` >= ' . $seats );        
	return $result;	         // Returns 'true' on success, 'false' on failure.
  }
}

// ******** UPDATE SESSION 2 PLACES **********

if (isset($RSGchecked) && ($RSGchecked === 1))  {
	
$update_seats2 = update_places2($id2, $seats);	
function update_places2($id2, $seats) {        
	global $modx;		
	$table = "`prefix_modx`.`xtra_session`";	    
	$update_seats2 = '`places` -' .$seats;		
	$result = $modx->db->update( '`places` = ' . $update_seats2, $table, '`id` = ' . intval($id2, 10) . ' AND `places` >= ' . $seats );        
	return $result;         // Returns 'true' on success, 'false' on failure.
  }
}


Rest of the processing script continues here....]]>
Twobears Jun 27, 2014, 12:35 AM https://forums.modx.com/thread/91805/1-0-12---updating-mysql-database-using-if-conditional#dis-post-501597