有人可以帮助我吗?
我已经在我的 WordPress 页面中使用了以下代码,但是很久以前我已经看过它了,老实说,我不记得怎么做调试它 - 去图...唯一改变的是数据库。
它的工作原理如下:
数据库布局:
。+-------+------------+------------+------------+------------+---------------+
| id | Naam | Metgesel | Kind1 | Kind2 | Email |
+-------+------------+------------+------------+------------+---------------+
| abc12 | Bobby | Caily | * | * | b@example.com |
| ... | ... | ... | ... | ... | ... |
+-------+------------+------------+------------+------------+---------------+
错误发生:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/.../public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(32) : eval()'d code on line 4
Invalid or no security key!
代码:
<script>
function invite(){
document.getElementById('invite').style.display=(document.getElementById('invite').style.display=='block')?'none':'block';
}
</script>
<script>
function returnHome(){
setTimeout(function () {window.location.href = 'http://example.com';},2000);
}
</script>
$part = $_REQUEST['id'];
if(isset($_GET["id"])){
$query = sprintf("SELECT * FROM `DATABASE`.`TABLE`
WHERE idquack='$part'",
mysql_real_escape_string($query));
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid or no security key';
die($message);
} else {
while ($row = mysql_fetch_assoc($result)) {
if ($row['Metgesel'] != "*"){
if ($row['Metgesel'] == "#"){
if ($row['Kind1'] != "*"){
if ($row['Kind2'] != "*"){
echo '<h1>' . $row['Naam'] . ", " . "Metgesel" . ", " . $row['Kind1'] . " en " . $row['Kind2'] . "</h1>";
} else {
echo '<h1>' . $row['Naam'] . ", " . "Metgesel" . " en " . $row['Kind1'] . "</h1>";
}
} else {
echo '<h1>' . $row['Naam'] . " en " . "Metgesel" . "</h1>";
}
} else{
if ($row['Kind1'] != "*"){
if ($row['Kind2'] != "*"){
echo '<h1>' . $row['Naam'] . ", " . $row['Metgesel'] . ", " . $row['Kind1'] . " en " . $row['Kind2'] . "</h1>";
} else {
echo '<h1>' . $row['Naam'] . ", " . $row['Metgesel'] . " en " . $row['Kind1'] . "</h1>";
}
} else {
echo '<h1>' . $row['Naam'] . " en " . $row['Metgesel'] . "</h1>";
}
}
} else {
echo '<h1>' . $row['Naam'] . "</h1>";
}
echo '<script>invite();</script>';
}
}
mysql_free_result($result);
} else{
echo 'Hold on tight - we're taking you home!';
echo '<script>returnHome();</script>';
}
答案 0 :(得分:1)
您想要更改此行:
$query = sprintf("SELECT * FROM `DATABASE`.`TABLE`
WHERE idquack='$part'",
mysql_real_escape_string($query));
到这一行:
$query = sprintf( "SELECT * FROM DATABASE.TABLE WHERE idquack='%s'", mysql_real_escape_string( $part ) );
您的错误是由于您将整个查询本身传递给mysql_real_escape_string函数,并且sprintf()正在寻找变量...这条线确实没有任何意义,因为您有它,但我提到的方式是一种调用它的正确方法。
我没有查看其余代码以查看是否还有其他问题,但请先尝试删除您提供的错误。