INSERT INTO使用数组不起作用

时间:2016-07-30 17:44:28

标签: php mysql sql pdo

这是我的问题:我不知道为什么,但我的PHP脚本不想在我这样构建的SQL表中添加一行:

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

我的PHP脚本是:

<?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);


?>

那么,任何人都有想法?谢谢: - )

编辑: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 个答案:

答案 0 :(得分:-2)

你在论证中忘了冒号:

$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
);