Reputation:
I'm trying to update informations in my database this is the html page:
<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>
this is 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);
and this is the method in my association class:
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();
}
}
i get this error
PDOStatement Object ( [queryString] => update
association
(nom
,adresse
,details
,date_creation
)VALUES(:nom,:adresse,:details,:date_creation) )Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(
nom
,adresse
,details
,date_creation
)VALUES('1','','','')' at line 1
Upvotes: 0
Views: 61
Reputation: 2040
The syntax for MySQL UPDATE
is:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
So you need:
$stmt = $conn->prepare(
"UPDATE `association` SET
`nom` =:nom,
`adresse` = :adresse,
`details` = :details,
`date_creation` = :date_creation");
Note this will update the entire association table so you should identify the rows you want to update with the WHERE
clause.
Upvotes: 1