Reputation: 19
I'm trying to insert values in the contents table. It works fine if I do not have a PHP variable inside VALUES. When I put the variable $address inside VALUES then this doesn't work
$lat= $_GET['lat']; //latitude
$lng= $_GET['lng']; //longitude
$address= $_GET['nom']; // this is an exmple
// $address= getAddress($lat,$lng); real fonction my probleme is how to call $address in values
$bdd->exec('INSERT INTO user(nom, prenom, Gsm, Email, Sexe, address) VALUES(\''.$_GET['nom'].'\' , \''.$_GET['prenom'].'\' , \''.$_GET['mobile'].'\' , \''.$_GET['Nemail'].'\' , \''.$_GET['sexe'].'\', '$address' )');
Upvotes: 1
Views: 77
Reputation: 2410
You would prefer prepared statement, safer and cleaner.
<?php
$stmt = $dbh->prepare("INSERT INTO user(nom, prenom, Gsm, Email, Sexe, address) VALUES(:nom, :prenom, :mobile, :Nemail, :sexe, :address)");
$stmt->bindParam(':nom', $_GET['nom'];
$stmt->bindParam(':prenom', $_GET['prenom'];
$stmt->bindParam(':mobile', $_GET['mobile'];
$stmt->bindParam(':Nemail', $_GET['Nemail'];
$stmt->bindParam(':sexe', $_GET['sexe'];
$stmt->bindParam(':address', $_GET['address'];
$stmt->execute();
?>
Upvotes: 3