PHP - 将变量从一个页面带到另一个页面并使用

发布于 2025-01-08 08:01:04 字数 2035 浏览 0 评论 0原文

我是一个真正的初学者,如果我犯了严重的错误,我很抱歉!

我想要做的事情我知道很简单,但我在文档中找不到相关帮助。

我想从“产品”页面中取出四个变量,然后我想将它们作为 html 表单的值发布,但我不知道如何做。

变量来自managebooks.php,需要在ammendbook.php中使用。

在managebooks.php中,我到ammendbook.php的链接如下:

echo "<tr>";
echo "<td>";
echo "<a href='amendbook.php?bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>Amend Entry</a>";
echo "</td>";

我希望将这四个变量带到下一页(ammendbook.php),我的表单代码如下:

<form id="adminlogin" name="login" action="amendbookupdate.php" method="post">
                    Book Title <br />
                    <input type="text" name="booktitle" value="<?php echo $bookname; ?>"></input><br />
                    Book Author(s)<br />
                    <input type="text" name="bookauthor" value="<?php echo $bookauthor; ?>"></input><br />
                    Book Publisher<br />
                    <input type="text" name="bookpub" value="<?php echo $bookpub; ?>" ></input><br />
                    ISBN-10 number (non-standard format)<br />
                    <input type="text" name="bookisbn" value="<?php echo $bookisbn; ?>"></input><br /><br />
                    <input type="submit" name="submit" value=" - Update Database - "></input>
                </form> 

我不确定还要包括什么,我尝试制作一个数组来看看这是否可行(因此回显变量如下所示:

<?php
    $bookname['bookname'] = $_GET['bookname'];
    $bookauthor['bookauthor'] = $_GET['bookauthor'];
    $bookpub['bookpub'] = $_GET['bookpub'];
    $bookisbn['bookisbn'] = $_GET['bookisbn'];
?>

但是这是错误的。

我也尝试在表单中输入:

<input type="text" name="booktitle" value="<?php echo $_SESSION['bookname'] ?>"></input><br />

但这也是错误的!

任何想法伙计们..

提前感谢您的阅读和任何帮助

I am a real beginner at this so sorry if I am makin awfull mistakes!

Want I want to do I know is very simple but I cant find the relevant help in my documentation.

I want to bring four variables out of a 'product' page, I then want to post these as the values of an html form but I am not sure how.

The variables come from managebooks.php and need to be used in ammendbook.php.

In managebooks.php my link to ammendbook.php is as follows:

echo "<tr>";
echo "<td>";
echo "<a href='amendbook.php?bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>Amend Entry</a>";
echo "</td>";

This i expected to bring that four variables with me to the next page (ammendbook.php) my form code is as follows:

<form id="adminlogin" name="login" action="amendbookupdate.php" method="post">
                    Book Title <br />
                    <input type="text" name="booktitle" value="<?php echo $bookname; ?>"></input><br />
                    Book Author(s)<br />
                    <input type="text" name="bookauthor" value="<?php echo $bookauthor; ?>"></input><br />
                    Book Publisher<br />
                    <input type="text" name="bookpub" value="<?php echo $bookpub; ?>" ></input><br />
                    ISBN-10 number (non-standard format)<br />
                    <input type="text" name="bookisbn" value="<?php echo $bookisbn; ?>"></input><br /><br />
                    <input type="submit" name="submit" value=" - Update Database - "></input>
                </form> 

I am not sure what else to include, I tried making an array to see if that would work (hense the echo variables like this:

<?php
    $bookname['bookname'] = $_GET['bookname'];
    $bookauthor['bookauthor'] = $_GET['bookauthor'];
    $bookpub['bookpub'] = $_GET['bookpub'];
    $bookisbn['bookisbn'] = $_GET['bookisbn'];
?>

But this is wrong.

I also in the form attempted to just put:

<input type="text" name="booktitle" value="<?php echo $_SESSION['bookname'] ?>"></input><br />

but this is also wrong!

Any ideas guys..

Thank you in advance for reading and any help!

[=

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

姐不稀罕 2025-01-15 08:01:04
method="post"

method="GET"

然后随意使用,

$_GET['bookpub']

无需声明。

例如:

test1.php:

<form action="test2.php" method="get">
Book Title <br />
<input type="text" name="booktitle" /><br />
<input type="submit" name="submit" value=" - Update Database - " />
</form> 

test2.php

<body>
<? echo $_GET["booktitle"]; ?>
</body>
method="post"

To

method="GET"

Then feel free to use

$_GET['bookpub']

Without declaring.

FOR EXAMPLE:

test1.php:

<form action="test2.php" method="get">
Book Title <br />
<input type="text" name="booktitle" /><br />
<input type="submit" name="submit" value=" - Update Database - " />
</form> 

test2.php

<body>
<? echo $_GET["booktitle"]; ?>
</body>
泛泛之交 2025-01-15 08:01:04

只需尝试:

$bookname = $_GET['bookname'];
$bookauthor = $_GET['bookauthor'];
$bookpub = $_GET['bookpub'];
$bookisbn = $_GET['bookisbn'];

在 ammendbook.php 的顶部,然后通过这些名称引用这些变量。这不是您要找的吗?我可能很困惑。

编辑:在将来自 GET 或 POST 数组的变量分配给变量之前,您应该始终对其进行清理。

Just try:

$bookname = $_GET['bookname'];
$bookauthor = $_GET['bookauthor'];
$bookpub = $_GET['bookpub'];
$bookisbn = $_GET['bookisbn'];

At the top of ammendbook.php and then refer to those variables by those names. Is that not what you're looking for? I may be confused.

Edit: You should always sanitize variables that come from the GET or POST arrays before assigning them to variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文