問題:
I want to pass JavaScript variables to PHP using a hidden input in a form.我想使用表單中的隱藏輸入將 JavaScript 變量傳遞給 PHP。
But I can't get the value of $_POST['hidden1']
into $salarieid
.但是我無法將$_POST['hidden1']
轉換爲$salarieid
。 Is there something wrong?有什麼不對?
Here is the code:這是代碼:
<script type="text/javascript">
// View what the user has chosen
function func_load3(name) {
var oForm = document.forms["myform"];
var oSelectBox = oForm.select3;
var iChoice = oSelectBox.selectedIndex;
//alert("You have chosen: " + oSelectBox.options[iChoice].text);
//document.write(oSelectBox.options[iChoice].text);
var sa = oSelectBox.options[iChoice].text;
document.getElementById("hidden1").value = sa;
}
</script>
<form name="myform" action="<?php echo $_SERVER['$PHP_SELF']; ?>" method="POST">
<input type="hidden" name="hidden1" id="hidden1" />
</form>
<?php
$salarieid = $_POST['hidden1'];
$query = "select * from salarie where salarieid = ".$salarieid;
echo $query;
$result = mysql_query($query);
?>
<table>
Code for displaying the query result.
</table>
解決方案:
參考一: https://en.stackoom.com/question/82qe參考二: https://stackoom.com/question/82qe