I use want to build a sinple form with some checkboxes to ask the user what subjects do they want to choose. and then the error shows up.
Error:
( ! ) Notice: Undefined variable: subjects in E:\Program Files\wamp\www\1\index.php on line 15
Call Stack
# Time Memory Function Location
1 0.0003 248664 {main}( ) ..\index.php:0
( ! ) Notice: Undefined index: in E:\Program Files\wamp\www\1\index.php on line 15
Call Stack
# Time Memory Function Location
1 0.0003 248664 {main}( ) ..\index.php:0
"index.php" File:
<?php
$hash = array (
0 => 'English',
1 => 'Math',
2 => 'Physics',
3 => 'History',
4 => 'Geography',
5 => 'Biology',
6 => 'Politics',
7 => 'P.E.',
8 => 'Art',
9 => 'Music',
);
if (isset ($_POST['submit'])) {
var_dump ($_POST[$subjects]);
}
?>
<html>
<body>
<form action="index.php" method="POST">
<h2>Choose Subject</h2>
<?php
$temple = '<label><input name="subjects[]" type="checkbox" value="';
$str = "";
foreach ($hash as $key => $value) {
$str = $str . $temple . $key . '" />' . $value . '</label>';
}
unset ($key);
unset ($value);
unset ($temple);
echo $str;
unset ($str);
?>
<input name="submit" type="submit" name="add_id_code">
</form>
</body>
</html>
P.S. I'm using wampserver.
Aucun commentaire:
Enregistrer un commentaire