删除PDO PHP后填充表
当用户登录时,他将进入一个页面,其中有一个表,该表在每一行上都填充了delete链接。如果单击delete链接,它将删除记录,但当它刷新页面时,表将不会加载此消息删除PDO PHP后填充表,php,pdo,Php,Pdo,当用户登录时,他将进入一个页面,其中有一个表,该表在每一行上都填充了delete链接。如果单击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_n
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_查询函数,您发布的代码中没有该函数。
因此,要么这些函数被意外地留在代码中,要么您只是发布了错误的代码。
请阅读您收到的错误消息。它们的信息量很大 显然:您的mysql用户名密码不正确,在这种情况下没有设置。没有,因为我第一次加载表页时,它将授予我访问权限。而binding:id将不起作用,您需要bind:table_idI重命名它以发布到这里,但是我会把我的一个放在代码中。你的错误消息与你的代码不匹配…我的代码中没有这些函数。我删除了所有这些,并改为PDO。我将再次仔细阅读我的代码,但上次检查时什么也没有。我仔细查看我的代码,发现我正在重定向到文件夹中的错误页面,该页面确实包含mysql_查询中的旧代码。我删除了旧页面,并更改了新页面中的代码以重定向到正确的页面。谢谢