I'm in the process of learning how to create a custom Drupal module, and have hit a snag with a database update.
My issue is in the form_submit hook. This is getting fired for the Insert, and my inserts are working fine. However, something is going wrong with the updates, but my troubleshooting code is not firing so I'm really having a hard time tracking this down. Here's the function in question:
function issues_project_submit($form_id, $form_values) {
global $user;
$start = NULL;
$end = NULL;
//preprocess the dates if needed
if (!empty($form_values['startdate'])) {
$start = strtotime($form_values['startdate']);
}
if (!empty($form_values['enddate'])) {
$end = strtotime($form_values['enddate']);
}
//For troubleshooting
watchdog('debugging', 'in submit');
if ($form_values['projectid'] == 0) {
$id = db_next_id('issues_projects');
$sql = 'insert issues_projects (';
$sql .= 'project_id, project_name, start_date, end_date, created_by, created_on) values (';
$sql .= $id .', ';
$sql .= "'". check_plain($form_values['projectname']) ."', ";
if ($start) {
$sql .= "'". date('Y-m-d', $start) ."', ";
}
else {
$sql .= "null, ";
}
if ($end) {
$sql .= "'". date('Y-m-d', $end) ."', ";
}
else {
$sql .= "null, ";
}
$sql .= $user->uid .", ";
$sql .= "'". date('Y-m-d') ."' ";
$sql .= ');';