0

我目前正在尝试从我的 SQL 数据库中回显信息,我必须对其进行编码才能有效地写入表中;现在,当我尝试回显信息时,在对其进行解码时,页面什么也没有显示,我不完全确定我在这一点上做错了什么。

<?php
$type = $_SESSION['SESS_ACC_TYPE'];
$login = $_SESSION['SESS_LOGIN_NAME'];
$log = base64_decode(''.$row['log'].'');
if ($type == '2') {
    $qry = "SELECT log FROM logs ";
    $result = mysqli_query($GLOBALS["___mysqli_ston"], $qry);
    while($row = mysqli_fetch_assoc($result)){
        echo ''.$log.'';
    }
}
if ($type == '1') {
    $qry = "SELECT log FROM logs WHERE login = '.$login.'";
    $result = mysqli_query($GLOBALS["___mysqli_ston"], $qry);
    while($row = mysqli_fetch_assoc($result)){
        echo ''.$log.'';
    }
} else {
    //do nothing
}
?>
4

2 回答 2

2

您的代码有很多错误:

我修好了它们。

$type  = $_SESSION['SESS_ACC_TYPE'];
$login = $_SESSION['SESS_LOGIN_NAME'];

if ($type == '2') {
    $qry = "SELECT `log` FROM `logs`;";
}
if ($type == '1') {
    $qry = "SELECT `log` FROM `logs` WHERE `login` = '" . $login . "';";
}

$result = mysqli_query($GLOBALS["___mysqli_ston"], $qry);
while($row = mysqli_fetch_assoc($result)) {
    echo base64_decode($row['log']);
}
于 2013-06-15T02:22:48.890 回答
0
since mysql 5.6.1 there are mysql base64 decode/encode functions

select FROM_BASE64('....') ...
select TO_BASE64('....') ...

http://base64decode.net/mysql-from-base64

于 2013-06-17T13:11:12.193 回答