你的複選框和提交按鈕應該是一個形式裏面,你的提交按鈕是HTML,而不是PHP。
<?php
/* Lets set the destination to the same file as the form. (see form action)
* That means, if someone has submitted the form, there will be data inside
* $_POST right now!
*/
// var_dump($_POST); <-- Can be used to quickly peek inside $_POST
if (!empty($_POST)) // Check if there is any data
{
save_data_to_file($_POST); // pseudo-code (should be replaced by you)
echo "success!"; // A success message perhaps?
exit(); // Stop here to not display the form below.
}
// If we come this far, it means the form has not been submitted.
// So lets display the form!
// You can have this line first in the file, or later,
// as long as you do this before you try to use it in your checkboxes.
$songList = explode("\n", file_get_contents('zmzonSongs.txt'));
?>
<h1>Welcome to Zmzon. Select songs below to add to your library</h1>
<form action="thisfile.php" method="POST">
<?php
// See, you can jump between PHP and HTML whenever you want.
foreach($songList as $songs){
echo "<input type='checkbox' ... ><br>";
}
?>
<input type="submit">
</form>
您可以將數據發送到另一個頁面或同一頁面,由「action」決定。 數據將位於變量$ _POST或$ _GET中(取決於您選擇的發送方法)。
查看這些全局變量的簡單方法是使用var_dump()。例如:
<pre>
<?php var_dump($_POST); ?>
再次更新
打開錯誤報告 –
我不知道該怎麼做。我對PHP幾乎一無所知,自從我開始這個任務以來,我幾乎沒有任何意義。 – user3308219
@ user3308219另一種方法是檢查error_log或查看您的頁面的源代碼。 –