当用户登录时,他将转到一个有表的页面,该表在每行上都填充了delete链接。如果我点击删除链接,它将删除记录,但当它刷新页面时,表将不会加载此消息。
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_query()
函数,该函数在您发布的代码中不存在。
所以,要么这些函数被意外地留在代码中,要么你只是发布了错误的代码。
请阅读您的错误信息。它们内容丰富。