【发布时间】:2018-05-03 02:57:05
【问题描述】:
我正在尝试在下面进行以下插入。当我只取字符串MZ�\0\0\0\0\0\0\0��\0\0�\0\0\0,直接放入insert语句中,就可以了。但是,当我通过我的函数获取它然后尝试插入时,当从该表中选择所有内容时,我得到一个空集。
if($_FILES)//check if cookies set
{
require_once 'DBLogin.php';
$conn = new mysqli($hn, $un, $pw, $db);
if($conn -> connect_error) die($conn->connect_error);
$username = $_REQUEST['uname'];
//echo "admin: ".$_SESSION['admin']."<br>";
if (!preg_match("/^[a-zA-Z0-9]+$/", $_POST['mname']))
{
echo "Invalid malware name. Only Numbers and Letters allowed". "<br>";
exit();
}
else if(!isset($_SESSION['check']) || !isset($_COOKIE['token']) ||$_SESSION['check'] !== hash('ripemd128', $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . $_COOKIE['token']))
{
echo "Need to login as Admin before can upload files.<br>";
exit();
}
else
{
verifyAdmin($conn);
$fileGood = checkFile($_FILES);
$entry = getSection($fileGood);
$entry = chooseSanitization($conn,$entry, $_FILES['file']['type']);
//$entry = mysql_entities_fix_string($conn,$entry);
if(checkExistence($conn, $_POST['mname'],$entry) === true)
{
echo "Malware sequence and/or name already in database. Please upload different name/sequence. <br>";
exit();
}
$title = $_POST['mname'];
$insertQuery = "Insert into malwarelist (malwareName, sequence) values ('$title','$entry')";
//$insertQuery = "Insert into malwarelist (malwareName, sequence) values ('$title','MZ�\0\0\0\0\0\0\0��\0\0�\0\0\0')";
$conn -> query($insertQuery);
echo "Malware has been added! <br>";
}
$conn->close();
}
function chooseSanitization($connection,$string, $fileType)
{
if ($fileType === 'text/plain')
{
return mysql_entities_fix_string($connection,$string);
}
else
{
return mysql_fix_string($connection,$string);
}
}
function mysql_entities_fix_string($connection, $string)
{
return htmlentities(mysql_fix_string($connection, $string));
}
function mysql_fix_string($connection, $string)
{
if (get_magic_quotes_gpc()) $string = stripslashes($string);
return $connection->real_escape_string($string);
}
如果我尝试执行“插入恶意软件列表(恶意软件名称,序列)值('$title','MZ�\0\0\0\0\0\0\0��\0\0�\0 \0\0')" 它有效,但如果我尝试这样做:插入恶意软件列表(malwareName,序列)值('$title','$entry')“。仅供参考,$entry 等于 MZ�\ 0\0\0\0\0\0\0��\0\0�\0\0\0,但是没有插入,为什么?
【问题讨论】:
-
WHERE 子句在将数据插入数据库时不能使用,因为它仅在我们需要读取或更新数据库中的任何值时使用。尽量避免 WHERE 子句,你的帖子的倒数第二行
-
我没有使用 where caluse。 “where”只是一个连接语句,告诉大家 $entry 等于什么值。我不在我的程序中使用它。