我是搞java的。公司有点php的活要干。所以问题是简单的。只是我不懂php
代码如下:
<?php
function checkLogin() {
echo $_POST["km"];
$km = $_POST["km"];
$link = mysql_connect ( 'localhost', 'sunrising', 'sunrising' ); print("link::::".$link );
mysql_select_db ( 'ams', $link ); print("connection ok");
$sql = "select username from km_user where km="."'".$km."'";
echo "sql::::".$sql;
$result = mysql_query($sql,$link); print("result::::".$result);
if ($result == null) { print("fail");
$outstr = "<script>alert('无权访问该系统');history.back();</script>";
echo $outstr;
}
else{
print("mygod");
$outstr = "<script>alert('UIHIH');history.back();</script>";}
}
checkLogin();
?>post接到的参数是有值的。而且在数据库里也是存在的。可就是跳不到else里面。
我感觉可能是sql语句拼的有问题。求大侠帮我看看。
代码如下:
<?php
function checkLogin() {
echo $_POST["km"];
$km = $_POST["km"];
$link = mysql_connect ( 'localhost', 'sunrising', 'sunrising' ); print("link::::".$link );
mysql_select_db ( 'ams', $link ); print("connection ok");
$sql = "select username from km_user where km="."'".$km."'";
echo "sql::::".$sql;
$result = mysql_query($sql,$link); print("result::::".$result);
if ($result == null) { print("fail");
$outstr = "<script>alert('无权访问该系统');history.back();</script>";
echo $outstr;
}
else{
print("mygod");
$outstr = "<script>alert('UIHIH');history.back();</script>";}
}
checkLogin();
?>post接到的参数是有值的。而且在数据库里也是存在的。可就是跳不到else里面。
我感觉可能是sql语句拼的有问题。求大侠帮我看看。
这里有值吗?
改成
if ($result == FALSE) {
试试