我正在使用以下脚本从留言簿中清除垃圾邮件链接,如果我将查询复制并通过phpmyadmin,它会正常工作,如果我在保存为php文件的浏览器中运行以下脚本,我会收到错误"无法执行查询:"。我看了一遍,看不出静脉注射做错了什么,有人能看到明显的静脉注射遗漏了什么吗?。
<?php
// Checks to see if the key value is set
if (isset($_GET['key'])) {
$key = $_GET['key'];
}
// If the key value isnt set give it a value of nothing
else
{$key = '';}
// Checks to see if the key value is valid to authenticate the user
if ($key == 'keycode'){
// If the key value is correct the user is granted access
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Select mysql db
mysql_select_db("towerroa_TRA", $con);
mysqli_query($con, "DELETE FROM `itsnb_phocaguestbook_items` WHERE `content` LIKE '%<a%'")or die ("Couldn't execute query: ".mysqli_error());
echo 'Spam Purged !';
}
else {
// Denies the user access if the key value isnt correct
echo '<h1>Access Denied !</h1>';}
问题是您混淆了mysql_
和mysqli_
。尝试修复以下问题;
mysqli_connect("localhost","user","password");
mysqli_select_db("towerroa_TRA", $con);
mysqli_query($con, "DELETE FROM `itsnb_phocaguestbook_items` WHERE `content` LIKE '%<a%'")or die ("Couldn't execute query: ".mysqli_error());
而不是;
mysql_connect("localhost","user","password");
mysql_select_db("towerroa_TRA", $con);
mysqli_query($con, "DELETE FROM `itsnb_phocaguestbook_items` WHERE `content` LIKE '%<a%'")or die ("Couldn't execute query: ".mysqli_error());
mysqli_select_db("towerroa_TRA", $con);
应该是
mysqli_select_db($con,"towerroa_TRA");
用mysqli_*
替换所有mysql_*
函数
尝试这个
<?php
// Checks to see if the key value is set
if (isset($_GET['key'])) {
$key = $_GET['key'];
}
// If the key value isnt set give it a value of nothing
else
{$key = '';}
// Checks to see if the key value is valid to authenticate the user
if ($key == 'keycode'){
// If the key value is correct the user is granted access
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Select mysql db
mysql_select_db("towerroa_TRA", $con);
mysql_query($con, "DELETE FROM `itsnb_phocaguestbook_items` WHERE `content` LIKE '%<a%'")or die ("Couldn't execute query: ".mysql_error());
echo 'Spam Purged !';
}
else {
// Denies the user access if the key value isnt correct
echo '<h1>Access Denied !</h1>';}