-1
<?php
include("db/dbconnect2.php");

$noMyKid1 = $_GET['noMyKid'];

echo $noMyKid1;

$sql= "SELECT namaAnak,noSijilLahir
FROM mohon a 
INNER JOIN tblstatus_tak_lengkap b on a.noMyKid=b.nomykid 
WHERE a.noMyKid='noMyKid1'";
$result = mysql_query($sql) or @error_die("Query failed : $sql " . mysql_error());

echo $noMyKid;
echo $namaAnak;
echo $noSijilLahir;
?>

I run this coding, but the output just appear for

echo $noMyKid1;,echo $noMyKid;

Why echo $namaAnak;and echo $noSijilLahir; not appear?

potashin
  • 44,205
  • 11
  • 83
  • 107
user3487681
  • 149
  • 1
  • 1
  • 9
  • In the SQL query you probably meant to say `WHERE a.noMyKid='$noMyKid1'` (you should add the $ if you are using the variable). Also, you run the query, which goes into `$result`, but you don't do anything with the result. It does not auto-populate variables from your query. You need to fetch the values first. – Always Learning Apr 14 '14 at 04:12
  • [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Phil Apr 14 '14 at 04:13

2 Answers2

2

Cause they are not defined. Also, you've forgotten $ sign(I guess, if there is a.noMyKid='noMyKid1' then sorry):

$sql= "SELECT namaAnak,noSijilLahir
FROM mohon a 
INNER JOIN tblstatus_tak_lengkap b on a.noMyKid=b.nomykid 
WHERE a.noMyKid='$noMyKid1'";

And to fetch you result set:

while($row = mysql_fetch_assoc($result)){
   echo $row['namaAnak'];
   echo $row['noSijilLahir'];
}
potashin
  • 44,205
  • 11
  • 83
  • 107
0

Because you are echoing empty variable without initialized any value on it:

This is full code may be working for you:

<?php
include("db/dbconnect2.php");

$noMyKid1 = $_GET['noMyKid'];

echo $noMyKid1;

$sql= "SELECT namaAnak,noSijilLahir
FROM mohon a 
INNER JOIN tblstatus_tak_lengkap b on a.noMyKid=b.nomykid 
WHERE a.noMyKid='$noMyKid1'";
$result = mysql_query($sql) or @error_die("Query failed : $sql " . mysql_error());

while ($row = mysql_fetch_array($result))
{
   echo $row['namaAnak'];
   echo $row['noSijilLahir'];
}
?>

And you have forgotten $ sign on your query string

WHERE a.noMyKid='$noMyKid1'";
Fariz Azmi
  • 713
  • 1
  • 6
  • 21