mysql_real_escape_string php

Nama yang pakai tanda petik satu / apostrophe, gmn dong querynya di mysql ?

Bismillah

Langsung saja kita pakai, mysql_real_escape_string


<?php

$user = "root";
$pass = "password_mysql";
$host = "localhost";
$conn = mysql_connect($host, $user, $pass);

if ( $conn) {
echo "koneks";
} else {
echo "putus";
}
$nama = "sa'diyah";
//$nama2 = mysql_real_escape_string($nama);

$nama = mysql_real_escape_string($nama);

mysql_select_db("polteku");

$query = mysql_query("select id,nama, alamat from person where nama = '$nama'" );

$num_rows = mysql_num_rows($query);

echo "" . $num_rows;

?>

<?php

$user = “root”;
$pass = “ahmids”;
$host = “localhost”;
$conn = mysql_connect($host, $user, $pass);

if ( $conn) {
echo “koneks”;
} else {
echo “putus”;
}
$nama = “sa’diyah”;
//$nama2 = mysql_real_escape_string($nama);

$nama = mysql_real_escape_string($nama);

mysql_select_db(“polteku”);

$query = mysql_query(“select id,nama, alamat from person where nama = ‘$nama'” );

$num_rows = mysql_num_rows($query);

echo “” . $num_rows;

?>

[/sourcecode]

Alhamdulillah

Advertisements