mysql_fetch_array() and mysql_num_rows() error

when i put the single quote in the url like http://xxxxx/xxxxx/dor/Test.php?nomor=1234400 the error message come out like like this

[b]Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\dor\Test.php on line 46

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\dor\Test.php on line 47[/b]

here the php code

[php]

Pengumuman Testing

 

 

Test Dulu Ah
PENGUMUMAN ONLINE
Kelulusan
SMA Negeri xxxx Jakarta
TAHUN AKADEMIK 2010/2011


<?php $username="root"; $password=""; $database="test1"; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $nomor = $_GET['nomor']; // inisialisasi nomor $query="SELECT * FROM murid WHERE Ujian = '$nomor'"; //sesuaikan nm_field "Ujian" dengan table murid di databaae... $result = mysql_query($query); $array = mysql_fetch_array($result); $rowResult = mysql_num_rows($result); $a = 'nomor yang anda masukan gagal'; ?> <?php if($rowResult==False): ?>

Maaf <?php echo "$a"; ?>

<?php else: ?>

Selamat! Nomor Ujian <?php echo $array['ujian'];?> dengan Nama <?php echo $array['Nama']; ?> dinyatakan <?php echo $array['Status']; ?>

<?php endif; ?>
SMAN xxxxxx Jakarta Selatan
Nomor Telepon 73111444
Fax 2145225456532 [/php]

i’m new in php language please anybody help me :frowning:

try mysql_fetch_assoc() instead of mysql_fetch_array()

get same error message

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\dor\Test.php on line 46

here the code

[php]<?php
$username=“root”;
$password="";
$database=“test1”;

mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( “Unable to select database”);

$nomor = $_GET[‘nomor’]; // inisialisasi nomor
$query=“SELECT * FROM murid WHERE Ujian = ‘$nomor’”; //sesuaikan nm_field “Ujian” dengan table murid di databaae…
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$rowResult = mysql_num_rows($result);
$a = ‘nomor yang anda masukan gagal’;
?>

<?php if($rowResult==False): ?>

Maaf <?php echo "$a"; ?>

<?php else: ?>

Selamat! Nomor Ujian <?php echo $row['ujian'];?> dengan Nama <?php echo $row['Nama']; ?> dinyatakan <?php echo $row['Status']; ?>

<?php endif; ?>
[/php]

:frowning:

gotta clean your $_GET input looks like?

http://www.php.net/manual/en/function.mysql-real-escape-string.php
[php]$nomor =mysql_real_escape_string( $_GET[‘nomor’] );[/php]

Thank you very much sir it works ;D thank youu sooo much

Sponsor our Newsletter | Privacy Policy | Terms of Service