-3

当用户登录时,他将转到一个有表格的页面,该表格被很好地填充,每一行都有删除链接。如果我单击删除链接,它将删除记录,但是当它刷新页面时,表格不会加载此消息。

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>"; 
4

1 回答 1

0

您发布的代码中缺少的错误消息提及mysql_query()功能。
因此,这些函数要么意外留在代码中,要么您只是发布了错误的代码。
请阅读您收到的错误消息。他们信息量很大。

于 2013-03-01T09:25:38.250 回答