在我的php代碼中,有一個表單中有多個提交按鈕,第一個表單的變量在點擊提交按鈕後分配值,第二種形式類似$ _POST []。在這裏我想使用第二次提交的第一次提交的值。如何使用另一個提交按鈕中的另一個提交按鈕內的變量php
我的代碼如下:
<?php
global $name;
//BLOCK1
if($_POST['formSubmit'] == "Register Yourself")
{
global $name;
$name = $_POST['name'];
echo $name;
};
// BLOCK 2
if($_POST['formSubmit1'] == "Register Yourself1")
{
global $name;
$id = $_POST['id'];
echo $id;
echo $name; // I want to print "$name" here
};
?>
<html>
<title>form</title>
<body>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<b> <label for='name'>Name: </label> </b>
<input type="text" name="name" maxlength="50" value="<?=$name;?>" />
<input type="submit" name="formSubmit" value="Register Yourself" />
<br/><br/>
<b> <label for='id'> id: </label> </b>
<input type="text" name="id" maxlength="50" value="<?=$id;?>" />
<input type="submit" name="formSubmit1" value="Register Yourself1" />
</form>
</body>
</html>
我試圖用給定here的概念。 在上面的程序中,我已經聲明變量$ name作爲全局內部和外部用於第二個。
請儘量找出錯誤,這樣我可以在第二塊內打印...
在此先感謝
您不必內外聲明它,他們是如果測試不起作用。根本不需要使用全局。 – Pitchinnate
我沒有得到你的意見....請澄清 – pali
你需要閱讀:http://php.net/manual/en/language.variables.scope.php – Pitchinnate