0

我的 PHP Msyql Check 数据有问题。来源将如下所示:

$cek_saldo=mysql_num_rows(mysql_query
("SELECT badge_id, bulan, jns_saldo FROM t_saldo WHERE badge_id='$badge_id' AND bulan='Januari' AND jns_saldo='Tabungan Wajib'"));

if ($cek_saldo > 0)
{
    include ("manage_saldo.php");
    echo "<div class='emp'>Saldo already added.</div>";
}
else
{
Save query data.
}

我的例子:
jns_saldo 是“Tabungan Wajib”
徽章 ID 是 165520
Bulan 是 Januari

因此,如果示例数据与表中相同,则给出消息“Saldo 已添加。”。如果没有,PHP 执行 else 语句,即保存数据。

4

2 回答 2

1

尝试回显执行的查询。在 phpmyadmin 中手动检查此查询。所以你可以找到问题。

$query="SELECT badge_id, bulan, jns_saldo FROM t_saldo WHERE badge_id='$badge_id' AND bulan='Januari' AND jns_saldo='Tabungan Wajib'";
    echo $query;
    $result=mysql_query($query);
    $cek_saldo=mysql_num_rows($result);
    if ($cek_saldo > 0)
    {
        include ("manage_saldo.php");
        echo "<div class='emp'>Saldo already added.</div>";
    }
    else
    {
    Save query data.
    }
于 2012-10-09T07:59:28.183 回答
0
$list = mysql_query("SELECT badge_id, bulan, jns_saldo FROM t_saldo WHERE badge_id='$badge_id' AND bulan='Januari' AND jns_saldo='Tabungan Wajib'");

if(mysql_num_rows($list) > 0){
    include ("manage_saldo.php");
    echo "<div class='emp'>Saldo already added.</div>";       
}else{
    Save query data.
}

或者

$list = mysql_query("SELECT COUNT(badge_id) FROM t_saldo WHERE badge_id='$badge_id' AND bulan='Januari' AND jns_saldo='Tabungan Wajib'");

$row = mysql_fetch_array($list)
$cek_saldo = $row[0];

if($cek_saldo  > 0){
        include ("manage_saldo.php");
        echo "<div class='emp'>Saldo already added.</div>";       
    }else{
        Save query data.
    }
于 2012-10-09T08:04:29.147 回答