簡體   English   中英

在另一個文件 php 中使用來自用戶的輸入

[英]Using input from the user in another file php

我不想在另一個文件中使用用戶的輸入。 因為現在我無法使用來自用戶的輸入(在 send.php 文件中),因為我不知道如何獲取這些輸入。

這是我的 INDEX.PHP :

<form> 
<input type="text" name="Username" placeholder="Username....">
<br>
<br>
<input type="text" name="Password" placeholder="Password....">
<br>
<br>
<div class="knop">
<a href="send.php">Inloggen</a>
</form>

我的 send.php :

include("index.php");

$username = "Username: ";
$us = $_POST['Username']; // I wan't to get the input that the user gave inside the index.php
$password = "Password: ";
$pass = $_POST['Password']; // I wan't to get the input that the user gave inside the index.php

只需在您的表單標簽中設置一個 action 屬性和 HTTP 方法,您不應該使用 href 屬性,因為它只會將您重定向到另一個頁面而不發送數據,而是使用帶有提交屬性的按鈕標簽

<form action="path/to/send.php" method="POST"> 
<input type="text" name="Username" placeholder="Username....">
<br>
<br>
<input type="text" name="Password" placeholder="Password....">
<br>
<br>
<div class="knop">
<button type="submit">Inloggen<button/>
</form>

現在您可以在send.php使用$_POST['Password']$_POST['Username']檢索數據,

並且您也不必在 send.php 中include您的 index.php。

我想在你使用 PHP 和 HTML 表單之前,你需要閱讀更多關於 PHP 和 HTML 的內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM