0

我正在使用以下脚本从我的留言簿中清除垃圾邮件链接,如果我将查询复制并传递到 phpmyadmin 它工作得很好,如果我在保存为 php 文件的浏览器中运行以下脚本,我会收到错误“不能执行查询:”。我已经看过了,看不到 iv 做错了什么,谁能看到任何明显的 iv 遗漏?

    <?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>';}
4

4 回答 4

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());
于 2013-04-29T09:14:56.397 回答
2
mysqli_select_db("towerroa_TRA", $con);

应该

mysqli_select_db($con,"towerroa_TRA");
于 2013-04-29T09:32:22.730 回答
1

try this

<?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>';}
于 2013-04-29T09:36:03.120 回答
1

将所有mysql_*功能替换为mysqli_*

于 2013-04-29T09:15:40.393 回答