gpt4 book ai didi

php - 变量不流动?

转载 作者:行者123 更新时间:2023-11-29 13:29:56 25 4
gpt4 key购买 nike

我正在尝试让我的编辑页面适用于我的简单新闻系统。我想要它做的是在单击时显示所有新闻项目,它确实如此,但随后我希望能够单击标题并重定向到交换机并显示一个包含该特定标题的所有信息的表单,然后就可以编辑它了。不幸的是,每当我点击标题时,什么也没有发生。

<html>
<head>
<link rel="stylesheet" type="text/css" href="includes/style.css" />
</head>

<body>
<div align="center" /><font size="20px;" />#test</font></div>
<?php include("includes/navigation.php"); ?>

<fieldset><legend>Article editting</legend>
<?php
$idGlobal;
include("includes/config.php");
global $idGlobal;
if(isset($_GET['x'])) {
$x = $_GET['x'];
switch($x) {

case "$idGlobal":
if(is_null($idGlobal)) {
// if $the_id variable is null (empty) it will display the message below.
echo("Error. No id pushed.");
} elseif(isset($idGlobal)) {
// if $the_id variable is set (is storing a variable) it will display the form below.
$result = mysql_query("SELECT * FROM posts WHERE id=$idGlobal") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo('<form action="includes/process.php?x=edit" method="post" />');
echo('<input name="title" type="text" value="$row[\'title\']"/><br />');
echo('<input name="date" type="text" value="$row[\'date\']"/><br />');
echo('<textarea rows="4" cols="50" name="text" />$row[\'text\'];</textarea><br />');
echo('<input name="author" type="text" value="$row[\'Author\']"/><br />');
echo('<input type="submit" />');
echo('</form>');
}
}
break;

default:
echo("<table>");
echo("<tr><th>ID</th><th>Title</th><th>Date</th><th>Author</th></tr>");
while($row = mysql_fetch_array($result)) {
$id = $row['id'];

echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo("<a href=\"edit.php?x=$id\" />" .$row['title'] . "</a>");
echo("</td><td>");
echo $row['date'];
echo("</td><td>");
echo $row['author'];
echo("</td></tr>");
$idGlobal = $id;
}
break;
}
} else {
echo("<table>");
echo("<tr><th>ID</th><th>Title</th><th>Date</th><th>Author</th></tr>");
while($row = mysql_fetch_array($result)) {
$id = $row['id'];

echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo("<a href=\"edit.php?x=$id\" />" .$row['title'] . "</a>");
echo("</td><td>");
echo $row['date'];
echo("</td><td>");
echo $row['author'];
echo("</td></tr>");
$idGlobal = $id;
}
}
?>
</fieldset>
</body>
</html>

最佳答案

将此行视为其余行的示例:

echo('<input name="title" type="text" value="$row[\'title\']"/><br />');

PHP中的变量插值仅发生在双引号字符串中,下标变量的插值需要将变量括在大括号中:

echo("<input name=\"title\" type=\"text\" value=\"{$row['title']}\"/><br />");

但请注意代码中的其他问题,包括 HTML 上下文中缺少文本转义,这很容易导致注入(inject)攻击,例如使用 " 输入。

关于php - 变量不流动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19615218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com