1

theres single quotes using in

$bio = "$user->description";

inserting DB like this;

<?
$sql = "insert into yyy (id, twitterid, 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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

2 Comments

Why do you -1 such a beautiful advice? Idiots. +1 from me dude.
Thanks Flavius. But I guess my tone is a little rude. I just hope the mysql extension is dropped in PhP 6.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.