簡體   English   中英

如何在MySQL插入中包含PHP變量

[英]How to include a PHP variable inside a MySQL insert

我正在嘗試在內容表中插入值。 如果我在VALUES中沒有PHP變量,它可以正常工作。 當我將變量$ address放在VALUES中時,這不起作用

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

您更喜歡准備好的聲明 ,更安全,更清潔。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM