我正在尝试回显我的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
}
?>
答案 0 :(得分: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']);
}
答案 1 :(得分:0)
since mysql 5.6.1 there are mysql base64 decode/encode functions
select FROM_BASE64('....') ...
select TO_BASE64('....') ...