Hi, I'm currently making a form where student sign up for their clubs(clubs-join.php).
Then, after they sign up, they will be sent to another page called clubs-result.php.
They will see their output like this:
Thanks for joining
Mr. a
You have joined the following clubs: (this is based on what clubs Mr a chose)
Gentlemen Club(GT)
Pet Society Club(PS)
However, I could only get this output:
Thanks for joining
Mr. a
You have joined the following clubs:
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Practical\Practical3\clubs-result.php on line 19
This is clubs-join.php
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Join TARUC's interest clubs</h1>
<form method="post" action="clubs-result.php">
Gender:
<input type="radio" name="gender" value="male"> Male
<?php if (isset($gender) && $gender == "male") {
echo "checked";
}
?>
<input type="radio" name="gender" value="female"> Female<br><br>
<?php if (isset($gender) && $gender == "female") {
echo "checked";
}
?>
Name:
<input type="text" maxlength="50" id="name" name="name"><br><br>
Mobile Phone:
<input type="text" maxlength="20" id="phone" name="phone"><br><br>
Interest Clubs: (Select 1 to 3 clubs)<br>
<!-- $clubs = array("Ladies Club", "Gentlemen Club", "DOTA and Gaming Club", "Manga and Comic Club", "Pet Society Club", "Farmville Club");-->
<?php
$club = array(
'LD' => 'Ladies Club',
'GT' => 'Gentlemen Club',
'DG' => 'DOTA and Gaming Club',
'MC' => 'Manga and Comic Club',
'PS' => 'Pet Society Club',
'FV' => 'Farmville Club'
);
foreach($club as $code => $clubName){
echo '<input type = "checkbox" class = "radio" value = "$club" name = "club" />';
echo $clubName;
echo'<br>';
}
?>
<!-- <input type = "checkbox" class = "radio" value = "Ladies Club(LD)" name = "club" />Ladies Club<br>
<input type = "checkbox" class = "radio" value = "Gentlemen Club(GT)" name = "club" />Gentlemen Club<br>
<input type = "checkbox" class = "radio" value = "DOTA and Gaming Club(GC)" name = "club" />DOTA and Gaming Club<br>
<input type = "checkbox" class = "radio" value = "Manga and Comic Club(MCC)" name = "club" />Manga and Comic Club<br>
<input type = "checkbox" class = "radio" value = "Pet Society Club(PS)" name = "club" />Pet Society Club<br>
<input type = "checkbox" class = "radio" value = "Farmville Club(FV)" name = "club" />Farmville Club<br>-->
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
<?php
// define variables and set to empty values
$name = $phone = $gender = $club = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input($_POST["name"]);
$phone = test_input($_POST["phone"]);
$gender = test_input($_POST["gender"]);
$club = test_input($_POST["club"]);
}
?>
</body>
</html>
This is clubs-result.php
<?php
$gender = $_POST["gender"];
$name = $_POST["name"];
$club = $_POST["club"];
echo "<h1>Thanks for joining</h1>";
if ($gender == "female") {
echo "<h2><b>Ms. $name</b></h2>";
} else {
echo "<h2><b>Mr. $name</b></h2>";
}
echo "You have joined the following clubs:<br>";
if (isset($club)) {
echo "<ul>";
foreach ($club as $code => $clubName) {
echo "<li>";
echo ($clubName($code));
echo "</li>";
}
echo "</ul>";
}
I tried changing the coding at $club part, but I still cant get the output that I want, can anyone point out my mistake?