我有一个问题让我发疯了一段时间,因为我就是想不通。
如果用户从表单创建帖子,我想回应类似“成功”的内容。
这是我到目前为止在我的 db-querys 文件中得到的:
if ($_REQUEST) {
$name = $_REQUEST['name'];
$price = $_REQUEST['price'];
$dateofevent = $_REQUEST['dateofevent'];
$time = $_REQUEST['time'];
$textinfo = $_REQUEST['textinfo'];
$leg = $_REQUEST['leg'];
$sql= $dbh->prepare("INSERT INTO events(name, dateofevent, time, price, leg, textinfo)
VALUE (:name, :dateofevent, :time, :price, :leg, :textinfo)");
$sql->bindParam(':name', $name);
$sql->bindParam(':dateofevent', $dateofevent);
$sql->bindParam(':time', $time);
$sql->bindParam(':price', $price);
$sql->bindParam(':leg', $leg);
$sql->bindParam(':textinfo', $textinfo);
$sql->execute();
$url = $_POST['name'];
header('Location: events.php?'.$url);
}
$_GET
然后,如果 url 正确,我尝试使用来回显某些内容。
到目前为止,这是我的视图文件中的代码:
if(isset($_GET[$url])) {
echo "success";
}
在这里我得到未定义的变量 $url 并且回显不起作用,没有显示。
我也尝试过类似的东西:
$url = 'path/to/event.php';
if (!$_SERVER['REQUEST_URI'] == $_SERVER[$url]) {
echo "success";
}
在这里我得到未定义的索引 path/to/event.php 并且回显也不起作用,没有显示。
谁能帮我解决我的问题?我是 php 新手,所以无法进一步了解这一点,我被困住了。