首先,我得到了一个数据库,我为不同的内容标记了不同的id。但是,我也做了一个评论框,我的评论都是用id=1,2,3…因此,每当我提交评论时,它都能够将其链接回我之前得到的正确id(而不是评论框id),即,如果我输入www.example.com/synopsis?id=1,我将回到那里。但是,我有一个delete.php文件链接到reload.php文件,其中页面被重新加载。由此,是否又无法回到剧情梗概呢?Id =1,而仅仅是概要?id =
这是我的代码提交评论按钮
<form action="synopsis.php?id=<?php $id =$_GET["id"]; echo $id; ?>" method="POST">
,这是有效的
这里是reload.php文件,这不起作用,我想让它回到概要?id=1每次点击delete
<?php
$id=$_GET['id'];
$link = mysql_connect("localhost", "root", "");
$refresh = mysql_query("SELECT id FROM dvd where id=$id",$link);
$row = mysql_fetch_assoc($result);
header("Location:synopsis.php?id=<?php $id =$_GET["id"]; echo $id; ?>");
?>
请帮
正确的字符串连接方式:
header("Location:synopsis.php?id=" . $id);
$id变量已经设置好了,不需要再设置了
$id=$_GET['id'];
$link = mysql_connect("localhost", "root", "");
$refresh = mysql_query("SELECT id FROM dvd where id=$id",$link);
$row = mysql_fetch_assoc($result);
header("Location:synopsis.php?id=". $id);
重复引号语法错误?
无论如何:
<?php
$id=$_GET['id'];
$link = mysql_connect("localhost", "root", "");
$refresh = mysql_query("SELECT id FROM dvd where id=$id",$link);
$row = mysql_fetch_assoc($result);
header("Location:synopsis.php?id=".$_GET['id']);
?>
<?php
用于从HTML模式切换到PHP模式,但在此代码中您已经处于PHP模式:
header("Location:synopsis.php?id=<?php $id =$_GET["id"]; echo $id; ?>");
在构建新的查询字符串时转义变量也是一种好做法:
header("Location: synopsis.php?" . http_build_query(array(
'id' => $_GET['id'],
)));