diff --git a/databaseOperations.php b/databaseOperations.php index 4e8210f..b99dc8d 100755 --- a/databaseOperations.php +++ b/databaseOperations.php @@ -269,6 +269,7 @@ function addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $desc { try { + $db->beginTransaction(); $request = $db->prepare('INSERT INTO event(event_title, event_localisation, event_dtstart , event_dtend, event_description, event_url, event_urlImage, event_contact) VALUES(:title, :localisation, :dstart, :dtend, :description, :url, :urlImage, :contact)'); $request->execute(array('title'=>$titre, 'localisation'=>$localisation, @@ -278,13 +279,19 @@ function addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $desc 'url'=>$url, 'urlImage'=>$urlImage, 'contact'=>$contact)); - //TODO add this Event to categories. Exemple : INSERT INTO eventCategorie(event_id, cat_id) VALUES(6, 14); $request->closeCursor(); - header("Location:index.php"); - exit; + $newEventId = $db->lastInsertId(); + $request = $db->prepare('INSERT INTO eventCategorie(event_id, cat_id) VALUES(:eventId, :catId)'); + foreach($catArray as $cat) + { + $request->execute(array('eventId'=>$newEventId, + 'catId'=>$cat)); + } + $db->commit(); } catch(PDOException $e) { + $db->rollBack(); //NOTE: change $e->getMessage() by an error message before going to production echo($e->getMessage()); die(); diff --git a/eventAdded.php b/eventAdded.php index 04c801d..ba2b60a 100644 --- a/eventAdded.php +++ b/eventAdded.php @@ -13,7 +13,6 @@ $contact = $_POST['contact']; $catArray = $_POST['chk_group']; addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $description, $url, $urlImage, $contact); ?> -