我正在使用以下脚本清除我的留言簿中的垃圾链接,如果我将查询复制并通过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>';}
答案 0 :(得分:2)
问题是你在混淆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());
答案 1 :(得分:2)
mysqli_select_db("towerroa_TRA", $con);
应该是
mysqli_select_db($con,"towerroa_TRA");
答案 2 :(得分:1)
将所有mysql_*
功能替换为mysqli_*
答案 3 :(得分:1)
试试这个
<?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>';}