Browse Source

updated addEvent to add categories at the same time

master
n0m1s 10 years ago
parent
commit
88b179d2da
2 changed files with 10 additions and 4 deletions
  1. +10
    -3
      databaseOperations.php
  2. +0
    -1
      eventAdded.php

+ 10
- 3
databaseOperations.php View File

@ -269,6 +269,7 @@ function addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $desc
{ {
try 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 = $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, $request->execute(array('title'=>$titre,
'localisation'=>$localisation, 'localisation'=>$localisation,
@ -278,13 +279,19 @@ function addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $desc
'url'=>$url, 'url'=>$url,
'urlImage'=>$urlImage, 'urlImage'=>$urlImage,
'contact'=>$contact)); 'contact'=>$contact));
//TODO add this Event to categories. Exemple : INSERT INTO eventCategorie(event_id, cat_id) VALUES(6, 14);
$request->closeCursor(); $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) catch(PDOException $e)
{ {
$db->rollBack();
//NOTE: change $e->getMessage() by an error message before going to production //NOTE: change $e->getMessage() by an error message before going to production
echo($e->getMessage()); echo($e->getMessage());
die(); die();


+ 0
- 1
eventAdded.php View File

@ -13,7 +13,6 @@ $contact = $_POST['contact'];
$catArray = $_POST['chk_group']; $catArray = $_POST['chk_group'];
addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $description, $url, $urlImage, $contact); addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $description, $url, $urlImage, $contact);
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>


Loading…
Cancel
Save