我的php raty腳本結構如下,它一直顯示「除零」。 似乎輸入結果不能寫入Mysql數據庫。除零誤差(PHP設置cookie問題)
我應該改變「$斷言東西= $ RS [ '總']/$ RS [ '選民'];?!非常感謝
原始腳本如下
include_once ('connect.php');
$score = $_POST['score'];
if (isset ($score)) {
$cookiestr = getip();
$time = time();
if (isset ($_COOKIE['person']) && $_COOKIE['person'] == $cookiestr) {
echo "1";
}
elseif (isset ($_COOKIE['rate_time']) && ($time -intval($_COOKIE['rate_time'])) < 60) {
echo "2";
} else {
$query = mysql_query("update raty set voter=voter+1,total=total+'$score' ");
$query = mysql_query("select * from raty");
$rs = mysql_fetch_array($query);
$aver = $rs['total']/$rs['voter'];
$aver = round($aver, 1) * 10;
// set COOKIE
setcookie("person", $cookiestr, time() + 3600 * 365);
setcookie("rate_time", time(), time() + 3600 * 365);
echo $aver;
}
}
function getip() {
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) {
$ip = getenv("HTTP_CLIENT_IP");
} else
if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} else
if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
$ip = getenv("REMOTE_ADDR");
} else
if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
$ip = "unknown";
}
return ($ip);
}
?>
我不是說我是一個心靈感應器嗎? –
感謝您的回覆,並且此方法正常工作! –