PHP mysql real escape string
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;
?>
Alhamdulillah
Great.. Btw, perintah:
ReplyDeleteecho " ". $num_rows; buat apaan?
Mendingan langsung aja:
echo $num_rows;
atau echo mysql_num_rows($query);
Keep coding guys.. :)
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
ReplyDeleteOk, sip..
ReplyDeleteKeep coding gan 👍🏻