當用戶登錄時,他將轉到一個有表格的頁面,該表格填充正確,每行有刪除鏈接。如果我點擊刪除鏈接,它將刪除記錄,但是當它刷新頁面時,表格將不會加載此消息。刪除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>";
顯然:你的密碼的mysql用戶名是不正確的(在這種情況下沒有設置)。 – 2013-02-28 18:11:31
不,因爲我第一次加載表格頁面,它會授予我訪問權限。 – emurray 2013-02-28 18:12:33
綁定':id'不會工作,你需要綁定:'table_id' – 2013-02-28 18:13:42