位置标头语法错误

时间:2011-11-01 11:14:04

标签: php

首先,我有一个数据库,我为不同的内容标记了不同的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每次我点击删除

<?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; ?>");
?>

请帮忙

4 个答案:

答案 0 :(得分:0)

纠正字符串连接:

header("Location:synopsis.php?id=" . $id);

答案 1 :(得分:0)

您已经设置了$ 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);

答案 2 :(得分:0)

重复quotes syntax errors?

  

无论如何:

<?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']);
?>

答案 3 :(得分:0)

<?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'],
)));
相关问题