Home  >  Article  >  Backend Development  >  读写数据库的有关问题

读写数据库的有关问题

WBOY
WBOYOriginal
2016-06-13 13:44:42827browse

读写数据库的问题

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->


require_once("session.php");
$web_root_part = "../";
require_once($web_root_part."lib/db.php");
require_once($web_root_part."lib/function.php");
header('Content-type:text/html;charset=utf-8');   

$AdminID = trim($_POST['AdminID']);
$PassWord = trim($_POST['PassWord']);
$Addtime = date("Y-m-d H:i:s");

$querySel = "select * from Admin where AdminID='".$AdminID."'";
if( !($result = $db->sql_query($querySel)) )
{
    message_die(DB_MESSAGE, 'Could not query Admin');
        
}else{
    
    $row = $db->sql_fetchrow($result);    
    //$db->sql_freeresult($result);
        
    if (empty($row['ID'])){
        
        $sql="insert into Admin (AdminID,PassWord,Editer,Addtime) values('".$AdminID."','".md5($PassWord)."','".$_SESSION['AdminID']."','".$Addtime."')";
        if( !($result = $db->sql_query($sql)) )
        {
            //echo $sql;
            message_die(DB_MESSAGE, 'Could not query Admin');
                
        }else{
                    
          echo "<script>location.replace('admin.php');</script>";    
        }    
        
    }else{
        
        echo "<script language="Javascript">";
        echo "alert('提示:管理员ID已存在,请重新输入!');";
        echo "history.go(-1);";
        echo "</script>"; 
    }
}        
?>




这个代码那里有问题呢? 怎么不管理员ID 有没有重复 都提示 管理员ID已存在,请重新输入 呢

------解决方案--------------------
代码看不出哪儿有问题,你的测试是否准确?
至于你说的$row['ID']没被清除,应该说不可能
------解决方案--------------------
把以下代码换成print_r($row);做调试,如果还有问题,把调试出来的结果发上来

echo "";
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