回声值不出现。

时间:2014-04-14 04:07:24

标签: php mysql sql echo

<?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;
?>

我运行此编码,但输出只显示

echo $noMyKid1;,echo $noMyKid;

为什么echo $namaAnak;and echo $noSijilLahir;没有出现?

2 个答案:

答案 0 :(得分:2)

因为它们没有定义。此外,您已忘记$签名(我猜,如果有a.noMyKid='noMyKid1'则抱歉):

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

并获取结果集:

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

答案 1 :(得分:0)

因为你在没有初始化任何值的情况下回显空变量:

这是完整的代码可能适合您:

<?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'];
}
?>

您忘记了$在您的查询字符串上签名

WHERE a.noMyKid='$noMyKid1'";