2013-04-29 101 views
0

我使用以下腳本來清除垃圾郵件鏈接從我的留言板,如果我複製並通過查詢到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

回答

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()); 
+0

我試過這個,仍然得到「無法執行查詢:」的錯誤信息:-( – 2013-04-29 09:24:39

+0

你有三重**檢查所有的數據庫名稱,表名和用戶/密碼等?什麼是部分''''後面的錯誤信息? – Dom 2013-04-29 09:35:04

1

替換所有mysql_*功能與mysqli_*

+0

Iv試過並仍然收到「Could not execute query:」錯誤信息:-( – 2013-04-29 09:26:04

2
mysqli_select_db("towerroa_TRA", $con); 

應該

mysqli_select_db($con,"towerroa_TRA"); 
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>';}