mysql real escape string php | java php laravel linux mysql sql bootstrap html css query java php laravel linux mysql sql bootstrap html css query: mysql real escape string php

Monday, May 16, 2016

mysql real escape string php

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

3 comments:

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

    atau echo mysql_num_rows($query);

    Keep coding guys.. :)

    ReplyDelete
  2. 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

    ReplyDelete
  3. Ok, sip..
    Keep coding gan 👍🏻

    ReplyDelete

saifiahmada.com adalah blog belajar programming Indonesia, membahas lengkap materi bahasa pemrograman: code HTML, CSS, Bootstrap, Desain, PHP, MySQL, coding Java, Query, SQL, dan dunia linux