绑定param不起作用

时间:2018-05-19 23:00:41

标签: php html

我正在尝试更新数据库中的信息 这是html页面:

<form method="post" action="update.php">
<fieldset>
<legend>Modifier informations:</legend>
  <div class="row">
<div class="col-sm-3">
  <label class="form-control">Nom</label>

</div>
<div class="col-sm-9">
  <input class="form-control" type="text" name="title">
</div>
</div>
<div class="row">
<div class="col-sm-3">
  <label class="form-control">Adresse</label>

</div>
<div class="col-sm-9">
  <input class="form-control" type="text" name="adresse">
</div>
</div>
<div class="row">
<div class="col-sm-3">
  <label class="form-control">Date fe FONDATION</label>

</div>
<div class="col-sm-9">
  <input class="form-control" type="date" name="date_creation">
</div>
</div>
<div class="row">
<div class="col-sm-3">
  <label class="form-control">Détails</label>

</div>
<div class="col-sm-9">
  <textarea class="form-control" name="details"></textarea>
</div>
 </div> 
  <br>
  <button style="float: right" type="submit" class="btn btn-primary">Valider</button>

</div>
</fieldset>
</form>
</div>

这是update.php

<?php
    require "DB/config.php";
    include "Service/Association.php";
    /*require '../connected.php';*/
    session_start();

    $ASS = new Association("1",$_POST["title"],$_POST["adresse"],$_POST["details"],$_POST["date_creation"]);

     $c=new config();
     $conn = $c->getConnexion();

    $ASS->ModifierAssociation($ASS,$conn);

这是我的关联类中的方法:

function ModifierAssociation($Animaux,$conn){
    try {

    $stmt = $conn->prepare("update  `association`( `nom`, `adresse`, `details`, `date_creation` )VALUES(:nom,:adresse,:details,:date_creation)");


        $nom=$Animaux->getnom();
        $stmt->bindParam(':nom',$nom);

        $adresse=$Animaux->getadresse();
        $stmt->bindParam(':adresse',$adresse);

        $details=$Animaux->getdetails();
        $stmt->bindParam(':details',$details);

        $date_creation=$Animaux->getdate_creation();
        $stmt->bindParam(':date_creation',$date_creation);

        print_r($stmt);

        $stmt->execute();
        }catch(PDOException $e)
        {
        echo "Error: " . $e->getMessage();
        }
    }

我收到此错误

  

PDOStatement对象([queryString] =&gt;更新associationnomadressedetailsdate_creation)VALUES(:nom,:adresse) ,:details,:date_creation))

     

错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在'(nomadressedetailsdate_creation附近使用正确的语法。值('1',' ','','')'在第1行

1 个答案:

答案 0 :(得分:1)

MySQL UPDATE的语法是:

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

所以你需要:

$stmt = $conn->prepare(
    "UPDATE  `association` SET  
        `nom` =:nom, 
        `adresse` = :adresse, 
        `details` = :details, 
        `date_creation` = :date_creation");

请注意,这将更新整个关联表,因此您应使用WHERE子句标识要更新的行。