Home >Backend Development >PHP Tutorial >凡有SQL查询的地方都市有个注意

凡有SQL查询的地方都市有个注意

WBOY
WBOYOriginal
2016-06-13 10:36:38829browse

凡有SQL查询的地方都会有个注意

Notice: Use of undefined constant mytime - assumed 'mytime' in /var/www/html/calsn/calresult.php on line 15
出现这个就是最后一行(15行)
$query="select * from empoloyee where empid='$empid'";
$result=mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);
if ($num>0)
{
$row=mysql_fetch_array($result);
$mytime=$row[mytime];

------解决方案--------------------
$row[mytime]

没打引号?
------解决方案--------------------
对啊,键名要引号啊
------解决方案--------------------
Use of undefined constant mytime

用了没有定义的常量,如果$row[mytime]中的mytime不见引号引起来,php会默认看成是常量,如果常量找不到它才会当做字符串,但是同时依然会抛出一个Notice提示,虽然影响不大,但是逻辑来的确有点不符,按思路来也是稍微影响了一点点性能(虽然这点点性能可以不在乎)
------解决方案--------------------
$mytime=$row['mytime'];

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn