-1

Here is my problem : I don't know why, but my PHP script doesn't want to add a row in my SQL table built like this :

My SQL table here - https://i.stack.imgur.com/W0hEc.png

My PHP script is :

<?php

$titre = $_POST['titre'];
$description = $_POST['description'];
$description = 'test';
$time_debut = $_POST['time_debut'];
$time_fin = $_POST['time_fin'];
$location_name = $_POST['location_name'];
$location_adresse = $_POST['location_adresse'];
$org_nom = $_POST['org_nom'];
$org_siteweb = $_POST['org_siteweb'];
$org_mail = $_POST['org_mail'];
$type = $_POST['type'];
$nb_repeat = $_POST['nb_repeat'];
$gap = $_POST['gap'];
$day = $_POST['day'];
$nb_week = $_POST['nb_week'];
$date = $_POST['date'];

try
{
    $bdd = new PDO('mysql:host=localhost;dbname=agenda_clgbt;charset=utf8', 'root', 'root');
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}

$req = $bdd->prepare("INSERT INTO agenda (titre, description, time_debut, time_fin, location_name, location_adresse, org_nom, org_siteweb, org_mail, type, nb_repeat, gap, day, nb_week, jour) VALUES (:titre, :description, :time_debut, :time_fin, :location_name, :location_adresse, :org_nom, :org_siteweb, :org_mail, :type, :nb_repeat, :gap, :day, :nb_week, :jour)");


$yolo = array(
    'titre' => $titre,
    'description' => $description,
    'time_debut' => $time_debut,
    'time_fin' => $time_fin,
    'location_name' => $location_name,
    'location_adresse' => $location_adresse,
    'org_nom' => $org_nom,
    'org_siteweb' => $org_siteweb,
    'org_mail' => $org_mail,
    'type' => $type,
    'gapnb_repeat' => $nb_repeat,
    'gap' => $gap,
    'day' => $day,
    'nb_week' => $nb_week,
    'jour' => $date
);

$req->execute($yolo);


?>

So, anyone has an idea ? Thank you :-)

EDIT : print_r($yolo) :

Array
(
    [:titre] => hello
    [:description] => test
    [:timedebut] => 12:00
    [:timefin] => 13:00
    [:locationname] => lieux
    [:locationadresse] => adresse
    [:orgnom] => org
    [:orgsiteweb] => siteweb
    [:orgmail] => mail
    [:type] => ponctuel
    [:gapnbrepeat] => 1
    [:gap] => 0
    [:day] => 0
    [:nbweek] => 0
    [:jour] => 2016-07-30
)
  • 1
    any error message? whats it? – Ghostff Jul 30 '16 at 17:45
  • 1
    check for errors via PHP/MySQL then come back and tell us what those are. The question is also missing the form for this, so make sure all those POST arrays contain values. http://php.net/manual/en/function.error-reporting.php --- http://php.net/manual/en/pdo.error-handling.php – Funk Forty Niner Jul 30 '16 at 17:45
  • Of course, all comments are being ignored. Don't expect a magic answer to appear. That one below; isn't the solution, believe me. So, I will not wait around much longer here. – Funk Forty Niner Jul 30 '16 at 17:55
  • Why dont put the insert query in a try/catch and see what kind of error is thrown? – msantos Jul 30 '16 at 18:01
  • not only catching errors, but print out (for now) the POST response array so you can see what inputs you're working with. Sometimes you might find something isn't what you expected it to be. – Rogue Jul 30 '16 at 18:10
  • All POST variables contain values. Try/Catch shows nothing. But I get a HY093 error launching `$req->errorInfo()` . – Pigeonormand Jul 30 '16 at 18:24
  • POST array and its values : `Array ( [:titre] => hello [:description] => test [:timedebut] => 12:00 [:timefin] => 13:00 [:locationname] => lieux [:locationadresse] => adresse [:orgnom] => org [:orgsiteweb] => siteweb [:orgmail] => mail [:type] => ponctuel [:gapnbrepeat] => 1 [:gap] => 0 [:day] => 0 [:nbweek] => 0 [:jour] => 2016-07-30 )` – Pigeonormand Jul 30 '16 at 18:27
  • Your placeholders' names are different. Now they are missing _. Check again: keys in parameters array shall look exactly the same as placeholders in SQL statement. – olegsv Jul 31 '16 at 10:36

1 Answers1

-2

You forgot colon in arguments:

$yolo = array(
    ':titre' => $titre,
    ':description' => $description,
    ':time_debut' => $time_debut,
    ':time_fin' => $time_fin,
    ':location_name' => $location_name,
    ':location_adresse' => $location_adresse,
    ':org_nom' => $org_nom,
    ':org_siteweb' => $org_siteweb,
    ':org_mail' => $org_mail,
    ':type' => $type,
    ':gapnb_repeat' => $nb_repeat,
    ':gap' => $gap,
    ':day' => $day,
    ':nb_week' => $nb_week,
    ':jour' => $date
);
olegsv
  • 1,422
  • 1
  • 14
  • 21
  • 1
    those are optional, believe me when I say this. – Funk Forty Niner Jul 30 '16 at 17:49
  • 1
    Read the following Q&A for yourself [Is the leading colon for parameter names passed to PDOStatement::bindParam() optional?](http://stackoverflow.com/questions/9778887/is-the-leading-colon-for-parameter-names-passed-to-pdostatementbindparam-opt) – Funk Forty Niner Jul 30 '16 at 17:52
  • There is no mentioning that colon can be safely omitted neither in FAQ you cited or in [PDO documentation](http://php.net/manual/en/pdostatement.bindparam.php). No examples have been supplied. – olegsv Jul 30 '16 at 17:59
  • 1
    Because, you're dead set on that link you gave in comments which is "undocumented" in it. The link I gave you http://stackoverflow.com/questions/9778887/is-the-leading-colon-for-parameter-names-passed-to-pdostatementbindparam-opt contains an answer http://stackoverflow.com/a/9778890/ which references it as part of the source core syntax https://github.com/php/php-src/blob/PHP-5.3.24/ext/pdo/pdo_stmt.c#L363. The colons in the arrays are not required. They are only required in the values. – Funk Forty Niner Aug 02 '16 at 14:10
  • @Fred-ii- as you can see, for parameters without colon in the C code prepends the colon. A workaround that may one day go away because the colon-less was not part of official spec. The presence of the feature in the source code does not make it part of official specification. – olegsv Aug 02 '16 at 14:24
  • 1
    @olegsv you're really making a lot of bluster about something which is not required regardless of how the C code handles it. Why are you arguing this so hard? – Jay Blanchard Aug 02 '16 at 14:39