这就是我的密码。 我不明白怎么了。 我从返回为'yyyy-mm-dd'的表评估中选择DateEval,然后将其与$dt进行比较。 如果它是相等的,那么消息是‘这个酒店已经评估’。 如果不是“错误”。 测试时,消息始终为“error”。
我尝试了一个MySql查询,将CURDATE()选择为$dt,并与dateeval进行比较。。。仍然没有任何结果。
抱歉,代码不好。
<?
$hotelSel = $_POST['D1'];
mysql_connect('localhost','root','') or die('Connexion Interrempu');
mysql_select_db('bdmarnissiomar') or die('bd not found');
$req1 = "select DateEval from evaluation where (IdHotel = '$hotelSel');";
$res1 = mysql_query($req1);
$dt = date('Y-m-d');
if($res1 == $dt)
echo('cet hotel est deja evalue');
else echo('erreur');
?>
对于php版本5.4或更高版本,此代码仅适用于
$req1 = "select DateEval from evaluation where (IdHotel = '$hotelSel');";
$res = mysqli_query($databaseconnection,$req1);
$dt = date('Y-m-d');
while($result = mysqli_fetch_assoc($res)){
if($result['DateEval']==$dt){
echo "True";
}else{
echo "False";
}
}
好吧,看来我已经解决了。 代码如下:
$d=date("Y-m-d");
$req="select * from evaluation where Idhotel='$hotelSel' and dateEval='$d'";
$res=mysql_query($req);
if(mysql_num_rows($res)!=0)
echo('Hotel already rated today');
else('**INSERTION**');