我需要一些關於如何使用POST傳遞變量而不使用會話的幫助。爲什麼PHP不使用在POST之外聲明的變量?
目前我的代碼並不顯示變量的值稱爲$ MYVARIABLE:
<?php
if(isset($_POST['testbutton'])){
if ($_POST['testbutton'] == 'Testing') {
echo $myvariable;
var_dump($_POST);
}
}
$myvariable = "hello world";
echo '<form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="post">';
echo '<input type="submit" value="Testing" name="testbutton"/>';
echo '</form>';
?>
我應該在更改代碼能在POST使用變量$ [「testbutton」]的一部分代碼?
您正在嘗試在定義它之前調用'$ myvariable'。移動 '$ myvariable =「hello world」;'頂部 – WheatBeak
定義它_before_您嘗試使用它 – jmoerdyk
移動'$ myvariable =「hello world」;'頂部 – devpro