2013-02-28 58 views
-3

當用戶登錄時,他將轉到一個有表格的頁面,該表格填充正確,每行有刪除鏈接。如果我點擊刪除鏈接,它將刪除記錄,但是當它刷新頁面時,表格將不會加載此消息。刪除PDO後填充表格PHP

Warning: mysql_query(): Access denied for user ''@'host' (using password: NO) 
Warning: mysql_query(): A link to the server could not be established in 
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given 

爲什麼它會讓我在第一次填充表格,然後又不會。這是我的刪除代碼。

$id_actividades = $_GET['idactividades']; 

$stmt = $dbh->prepare("DELETE FROM guaynabodb.actividades WHERE idactividades=:id_actividades"); 

$stmt -> bindParam(':id_actividades', $id_actividades); 
    try{ 
     $stmt->execute(); 
    } 
    catch (PDOException $ex) { 
    echo $ex->getMessage(),'Cannot delete',"\n"; 

     } 
     header('Location: actividades.php');//To redirect 
     exit; 

這是我有表格的頁面的代碼。它會在您登錄後加載,但如果我刪除了一條記錄,它將不會加載。

include('../includes/dbschema.php'); 
     $stmt = $dbh->prepare("SELECT * FROM actividades"); 
      $stmt->execute(); 
    print " <h1 id=\"h2title\">Calendario de Actividades</h1><br/><br/>";//Print the title header 

      echo "<table id=\"premiacionguaynabo\"> <tr> <th> No. </th> <th> Fecha </th> <th> Torneo </th> <th> Lugar </th> <th> Organizador </th> <th> Opciones </th> </tr>"; //The table and the headers are created 

      $tno = 0; 

       $result = $stmt->fetchall(PDO::FETCH_ASSOC); 

       foreach($result as $line){ 
       $tno = $tno + 1; 
    $id = $line["idactividades"]; 
    print "<tr class=\"alt2\">"; 

    print "<td id=\"idtorneo\"> $tno </td>"; 
    print "<td class=\"fechatorneo\"> " . $line['fecha_inicial'] . " al " . $line['fecha_final'] . "</td>"; 
    print "<td> <a id=\"plinks\" href=\"$picture\" rel=\"lightbox\" target=\"_top\" title=\"Flyer del Torneo\"> " . $line['ntorneo'] . " </a></td>"; 
    print "<td>" . $line['ltorneo'] . "</td>"; 
    print "<td>" . $line['otorneo'] . "</td>"; 

    print "<td id=\"idtorneo\"> <a id=\"udlinks\" href=\"uactividades.php?idactividades=$id\"> Edit </a> <a id=\"udlinks\" onclick=\"return confirmDelete()\" href=\"dactividades.php?idactividades=$id\"> Delete </a></td>"; 
    print "</tr>"; 

     } 

    print "</table>"; 
+0

顯然:你的密碼的mysql用戶名是不正確的(在這種情況下沒有設置)。 – 2013-02-28 18:11:31

+0

不,因爲我第一次加載表格頁面,它會授予我訪問權限。 – emurray 2013-02-28 18:12:33

+0

綁定':id'不會工作,你需要綁定:'table_id' – 2013-02-28 18:13:42

回答

0

錯誤消息提到mysql_query()功能,該功能在您發佈的代碼不存在的。
因此,無論是這些功能都遺留在代碼中,或者您只是發佈了錯誤的代碼。
請閱讀您的錯誤消息。他們的信息很豐富。

+0

我的代碼中沒有這些功能。我將其全部刪除並更改爲PDO。我會再次仔細閱讀我的代碼,但沒有最後一次檢查。 – emurray 2013-03-01 13:13:02

+0

我仔細查看了我的代碼,發現我正在重定向到我的文件夾中有一個錯誤的頁面,該頁面的確有來自mysql_query的舊編碼。我刪除了舊頁面,並更改了新頁面中的代碼以重定向到正確的頁面。謝謝。 – emurray 2013-03-01 13:40:18