iT邦幫忙

0

from 傳到 php ,再擷取 php 收到的值 ,回到from

yincahp 1 月前5064 瀏覽

你好,想問我該如何傳回值…

///////檔案A.php是這樣的////////

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> A.php</title>
</head>
<body>
<form name ="login" method="post" action="B.html">
名稱:<input type="text" name="User" size="15"/><br/>
密碼:<input type="password" name="Pass" size="15"/><br/>
地址:<textarea name="Address" rows="5" cols="50"></textarea><br/>
<input type = "hidden" name="Type" value="Member"/><br/>
<input type="submit" value = "註冊使用者"/>
</form>
<input type="text" name="User" size="15" valed="User">
</body>
</html>

//////檔案B.php是這樣的//////////

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> B.php</title>
</head>
<body>
<?php
$username = $_POST["User"];
$password = $_POST["Pass"];
print "姓名:" .$username."<br/>";
print "密碼:" .$password."<br/>";
$address = $_POST["Address"];
print "地址: <br/>" .nl2br($address)."<br/>";
$type = $_POST["Type"];
print "種類:" .$type."<br/>";
?>
</body>
</html>

開啟A.php輸入欄位之後,按下註冊使用者,想把輸入的值顯示在原本輸入的表格裡,我該怎麼做呢...

2 個回答

0
leotse
iT邦新手 5 級 ‧ 1 月前

意思是form傳回A.php嗎?
可以在form之前加上php variable.
再在form 內加上value= php variable.
從書學到的:PHP、MySQL與JavaScript學習手冊(第四版)
http://www.books.com.tw/products/0010685274
當然書內的比我做的更好,我覺得很值得買。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> A.php</title>
</head>
<body>
<?php
if (isset($_POST['User']))
  $User = $_POST['User'];
else
  $User = "";

if (isset($_POST['Pass']))
  $Pass = $_POST['Pass'];
else
  $Pass = "";

if (isset($_POST['Address']))
  $Address = $_POST['Address'];
else
  $Address = "";

echo <<<form
<form name ="login" method="post" action="A.php">
名稱:<input type="text" name="User" size="15" value="$User"/><br/>
密碼:<input type="password" name="Pass" size="15" value="$Pass"/><br/>
地址:<textarea name="Address" rows="5" cols="50"/>$Address</textarea><br/>
<input type = "hidden" name="Type" value="Member"/><br/>
<input type="submit" value = "註冊使用者"/>
</form>
form;
?>
</body>
</html>
0
harry789111
iT邦新手 4 級 ‧ 1 周前

用session看看~

我要發表回答

立即登入回答