开发者

how to mysql_real_escape_string SQL Query?

theres single quotes using in

$bio = "$user->description";

inserting DB like this;

<?
$sql = "insert into yyy (id, twi开发者_高级运维tterid, twitterkullanici, tweetsayisi, takipettigi, takipeden, nerden, bio, profilresmi, ismi) values ('', '$id', '$twk', '$tws', '$tkpettigi', '$tkpeden', '$nerden', '$bio', '$img', '$isim')";

$ak = mysql_query("select * from yyy where twitterid = '$id'");
if (mysql_num_rows($ak) == 0) {
    $sonuc = mysql_query($sql) or die(mysql_error());
    echo "ciciş listesine eklendin :)"; 
}
elseif (mysql_num_rows($ak) == 1) {
    $sonuc = "zaten ciciş olarak eklenmişsin. ikinci kere eklemeye ne gerek var :)";
}

?>

how can i mysql_real_escape_string the $bio correctly?


Make sure you establish a connection to your MySQL database first.

$sql = "insert into yyy (id, twitterid, twitterkullanici, tweetsayisi, takipettigi, takipeden, nerden, bio, profilresmi, ismi) values ('', '$id', '$twk', '$tws', '$tkpettigi', '$tkpeden', '$nerden', '" . mysql_real_escape_string($bio) . "', '$img', '$isim')";

FYI, this could have easily been found with a Google search or using the PHP documention.

Also, you should use this for any strings and/or user submitted data. Not just select fields.


You don't. Start using parameterized queries with mysqli or better, PDO

Example from the php doc with PDO :

<?php
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);

// insert one row
$name = 'one';
$value = 1;
$stmt->execute();

// insert another row with different values
$name = 'two';
$value = 2;
$stmt->execute();
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜