首页 > 解决方案 > PHP 变量 $id =$_GET('id') 有值但不能在代码中工作

问题描述

我目前正在尝试使用 php 制作一个基本网站,在其中我基本上可以编辑博客等。当 i9 双击当前文本时,我已经创建了它,以便打开 iframe 弹出窗口以更改文本。此 iframe 的 src 为editbox.php?id=<?php echo $id ?>($id 适用于父页面)。

问题是代码中的 $Id 似乎在 $query 部分中没有得到识别,即使它似乎具有正确的值

iframe 页面的代码如下:

<?php

include_once('../includes/connection.php');
include_once('../includes/article.php');

$article = new Article;
$id =$_GET['id'];
print_r($id);

$data = $article->fetch_data($id);

if (isset($_POST['content'])) {
    $content = $_POST['content'];
    $uid =$_GET['id'];

    $query = $pdo->prepare("UPDATE articles SET article_content='$content' WHERE article_id='$id'");

    $query->execute();?>

    <script>parent.location.href=parent.location.href</script>

        <?php }?> 

<script>
function textAreaAdjust(element){
     element.style.height = "auto"
     element.style.height = (25+element.scrollHeight)+"px";
     }</script>


<link rel="stylesheet" href="../Assets/style2.css" />    
<form action="editbox.php" method="post" autocomplete="off">    
<textarea autofocus="true" onfocus="textAreaAdjust(this);" onkeyup="textAreaAdjust(this)" cols="157" placeholder="Content" name="content" ><?php echo $data['article_content']?></textarea><br /><br />
<input type="Submit" value="Add article" />
</form>

奇怪的是 print_r 返回一个 3 这是它应该返回的,但由于某种原因它不起作用。

如果我将它从$id =$_GET('id')to更改它也可以工作,$id=3但由于 id 是动态的,我不能这样做。

对不起,如果上面的代码有其他问题,我是新手。

标签: phppdoget

解决方案


推荐阅读