我的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
布兰是Januari
因此,如果示例数据与表中的相同,则给出消息“Saldo已添加”。 如果没有,PHP执行else语句,即保存数据。
答案 0 :(得分: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.
}
答案 1 :(得分: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.
}