删除mysql行如果包含某些内容不起作用

问题描述:

我使用以下脚本来清除垃圾邮件链接从我的留言板,如果我复制并通过查询到phpmyadmin它工作得很好,如果我在浏览器中运行以下脚本保存作为一个PHP文件,我收到错误“无法执行查询:”。我仔细看了看,看不出iv做错了什么,任何人都可以看到任何显而易见的iv错过了?删除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); 
    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

,什么是你想不出错误执行查询?你也可以在每个地方使用不推荐使用的'mysql_'函数,不用'mysqli_query'部分。将所有内容更改为'mysql_ *'查询或'mysqli_ *'查询。 'mysqli_'强烈建议! – 2013-04-29 09:15:01

+0

有趣的是,它不能执行查询。 – 2013-04-29 09:19:35

+0

而不是$ con = mysql_connect(“localhost”,“user”,“password”); TRY $ con = mysql_connect(“localhost”,“user”,“password”)或die(mysql_error()); - 这是否给你任何错误?您的代码中的mysqli_query是否为mysql_query? – bestprogrammerintheworld 2013-04-29 09:41:09

问题是你在混合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()); 
+0

我试过这个,仍然得到“无法执行查询:”的错误信息:-( – 2013-04-29 09:24:39

+0

你有三重**检查所有的数据库名称,表名和用户/密码等?什么是部分''''后面的错误信息? – Dom 2013-04-29 09:35:04

替换所有mysql_*功能与mysqli_*

+0

Iv试过并仍然收到“Could not execute query:”错误信息:-( – 2013-04-29 09:26:04

mysqli_select_db("towerroa_TRA", $con); 

应该

mysqli_select_db($con,"towerroa_TRA"); 

试试这个

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