繁体   English   中英

在 php 标签外引用变量

[英]Referencing a variable outside php tag

我有一个像这样设置的表格

<DOCTYPE HTML>

<html>
    <head>
    </head>

    <body>

<? php

    $id = $_GET['id'];

    $conn = mysqli_connect('localhost', 'nabeel', 'nab33l', 'rabbi');
    $query = "SELECT * FROM poetry WHERE id = ".$id.";"

    $result = mysqli_query($conn, $query);
    $rows = mysqli_fetch_assoc($result);

    $Id = $rows[Id];
    $title = $rows[title];
    $author= $rows[author];
    $entry= $rows[entry];

        <form method="post" action="../">

            <label>ID</label><br>
            <input type="text" id="" name="Id" value='$Id'><br>

            <label>TITLE</label><br>
            <input type="text" id ="" name= "title" value=$title><br>

            <label>Author</label><br>
            <input type="text" id="" name= "author" value=$author><br>

            <label>Entry</label><br>
            <input type="text" id="" name= "entry" value=$entry><br>

            <label>Time & Date</label><br>
            <input type="datetime-local" id="" name= "timeanddate" value=$timeanddate ><br>

            <input type= 'hidden' name='form_submitted', value='1'>
            <br>
            <input type="submit" value="Submit" ><br>
?>
        </form>
    </body>

</html>

现在我似乎无法在其他任何地方调用 php 标记中声明的变量。 我可以在 php 标签内移动表单,但我想知道是否有一些正确的方法来实现这一点。

您需要在<?php echo $variable ?>周围放置一个<?php echo $variable ?> (你可以在全局声明它)

顺便说一下,如果变量是用户输入,你就有了一个完美的 XSS 向量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM