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

Published by

saifiahmada

Begin a big Process with a bit trying

3 thoughts on “mysql_real_escape_string php”

  1. Great.. Btw, perintah:
    echo ” “. $num_rows; buat apaan?
    Mendingan langsung aja:
    echo $num_rows;

    atau echo mysql_num_rows($query);

    Keep coding guys..🙂

    1. terima kasih untuk komentarnya bro, echo ” “. $num_rows; niat saya codingnya menjadi ini bro -> echo ”Jumlah data adalah = “. $num_rows; maklum bro baru belajar php hehe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s