forked from science-ation/science-ation
Added an error check in saving the user, avoiding duplicate keys on an insert if bad data is passed in. Touched up the error output to make finding errors a pinch easier.
This commit is contained in:
parent
6b94ef5c76
commit
a6544f40c4
21
user.inc.php
21
user.inc.php
@ -636,7 +636,7 @@ function user_save(&$u)
|
|||||||
mysql_query("UPDATE user_roles SET active='{$u['roles'][$r]['active']}' WHERE roles_id='{$u['roles'][$r]['roles_id']}' AND users_id='{$u['id']}'");
|
mysql_query("UPDATE user_roles SET active='{$u['roles'][$r]['active']}' WHERE roles_id='{$u['roles'][$r]['roles_id']}' AND users_id='{$u['id']}'");
|
||||||
if(mysql_error() != '') break;
|
if(mysql_error() != '') break;
|
||||||
}
|
}
|
||||||
if(mysql_error() != '') return mysql_error();
|
if(mysql_error() != '') return "SQLERR1: " . mysql_error();
|
||||||
|
|
||||||
$fields = array('salutation','firstname','lastname',
|
$fields = array('salutation','firstname','lastname',
|
||||||
'phonehome','phonework','phonecell','fax','organization',
|
'phonehome','phonework','phonecell','fax','organization',
|
||||||
@ -681,7 +681,7 @@ function user_save(&$u)
|
|||||||
$query = "UPDATE users SET $set WHERE id='{$u['id']}'";
|
$query = "UPDATE users SET $set WHERE id='{$u['id']}'";
|
||||||
mysql_query($query);
|
mysql_query($query);
|
||||||
}
|
}
|
||||||
if(mysql_error() != '') return mysql_error();
|
if(mysql_error() != '') return "SQLERR2: " . mysql_error();
|
||||||
|
|
||||||
// Save the other user data that is not stored in the users table
|
// Save the other user data that is not stored in the users table
|
||||||
|
|
||||||
@ -697,7 +697,7 @@ function user_save(&$u)
|
|||||||
mysql_query($query);
|
mysql_query($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mysql_error() != '') return mysql_error();
|
if(mysql_error() != '') return "SQLERR3: " . mysql_error();
|
||||||
|
|
||||||
if( // if this user has an altered available judging times selection, we need to save it
|
if( // if this user has an altered available judging times selection, we need to save it
|
||||||
array_key_exists('available_times', $u) &&
|
array_key_exists('available_times', $u) &&
|
||||||
@ -721,7 +721,7 @@ function user_save(&$u)
|
|||||||
mysql_query($query);
|
mysql_query($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mysql_error() != '') return mysql_error();
|
if(mysql_error() != '') return "SQLERR3: " . mysql_error();
|
||||||
|
|
||||||
if( // if this user has an altered event availability selection, we need to save it
|
if( // if this user has an altered event availability selection, we need to save it
|
||||||
array_key_exists('available_events', $u) &&
|
array_key_exists('available_events', $u) &&
|
||||||
@ -729,13 +729,14 @@ function user_save(&$u)
|
|||||||
){
|
){
|
||||||
mysql_query("DELETE FROM schedule_users_availability_link WHERE users_id = {$u['id']}");
|
mysql_query("DELETE FROM schedule_users_availability_link WHERE users_id = {$u['id']}");
|
||||||
if(count($u['available_events']) > 0){
|
if(count($u['available_events']) > 0){
|
||||||
$query = "INSERT INTO schedule_users_availability_link (users_id, schedule_id) VALUES (" . $u['id'] . ", ";
|
$eventList = array_unique($u['available_events']);
|
||||||
$query .= implode('), (' . $u['id'] . ', ', $u['available_events']);
|
foreach($eventList as $eventId){
|
||||||
$query .= ")";
|
$query = "INSERT INTO schedule_users_availability_link (users_id, schedule_id) VALUES (" . $u['id'] . ", " . $eventId . ")";
|
||||||
mysql_query($query);
|
mysql_query($query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mysql_error() != '') return mysql_error();
|
if(mysql_error() != '') return "SQLERR4: " . mysql_error();
|
||||||
|
|
||||||
if( // if this user has an altered selection of volunteer positions, we'll need to change that too
|
if( // if this user has an altered selection of volunteer positions, we'll need to change that too
|
||||||
array_key_exists('volunteer_positions', $u) &&
|
array_key_exists('volunteer_positions', $u) &&
|
||||||
@ -749,7 +750,7 @@ function user_save(&$u)
|
|||||||
mysql_query($query);
|
mysql_query($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mysql_error() != '') return mysql_error();
|
if(mysql_error() != '') return "SQLERR5: " . mysql_error();
|
||||||
|
|
||||||
/* Record all the data in orig that we saved so subsequent
|
/* Record all the data in orig that we saved so subsequent
|
||||||
* calls to user_save don't try to overwrite data already
|
* calls to user_save don't try to overwrite data already
|
||||||
|
Loading…
Reference in New Issue
Block a user