猿问

无法通过 if 语句检查查询

我想检查图像的路径是否为 NULL,但如下所示的 select 查询后的 if 语句不起作用;代码直接传递给else语句并在else语句中显示div,所以任何可以帮助我的人请...


<div class="adminLeft">

<?php 

$userID=$_SESSION['userID'];

$sql="SELECT path from cim WHERE userID='$userID'";

$res=mysql_query($sql);

if ($res==NULL)

{

?>

<div class="card">

<p> <img class ="card-img-top" src="/images/picture-profile.jpg"></p> 

</p>    

</div>

<br>

<form id="uploadprofpic" action="up.php" enctype="multipart/form-data" 

method="post">

<p> <input type="file" name="pic" accept="image/*"></p>

<input name="submit" class="formbutton" value="Upload your Photo" 

type="submit" id="submitReport"/>

</form>

<?php }

else {?>

<div class="card">

<p> <img class ="card-img-top" src=""></p> 

}

?> </p>

</div>


慕尼黑8549860
浏览 122回答 3
3回答

30秒到达战场

您正在检查字符串“NULL”,将其更改为 justNULL将检查它是否返回NULL<?php&nbsp;if ($res == NULL){?><div class="card">&nbsp; &nbsp; &nbsp; &nbsp;<p> <img class ="card-img-top" src="/images/picture-profile.jpg"></p>&nbsp;<?php }?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>所以现在如果它返回NULL,它将显示 div。顺便说一句,你最终没有正确关闭 php,你>?应该是?>

qq_笑_17

尝试像这样的 is_null 函数:if&nbsp;(is_null($res)){}

万千封印

使用根本null不"NULL"if&nbsp;($res==null){ }
随时随地看视频慕课网APP
我要回答