Jump to content

Lim

New Members
  • Posts

    2
  • Joined

  • Last visited

Lim's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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?
  2. Hi, I started to learn php recently, I need to create a table with 10 rows and 15 columns. However, I need to to enhance the table by displaying an alternate background color of “pink” and “white” for each table cell. I need to follow this requirement: • If row index + column index is an even number, use pink color. • Otherwise, use white color. Below is the code: <?php echo "<table style= 'border: 1px solid'>"; define("ROW", 10); define("COL", 15); for($i = 1; $i <= ROW; $i++){ echo "<tr style= 'border: 1px solid; height: 20px'> \n"; for($j = 1; $j <= COL; $j++){ $sum = $i + $j; $td = "<td style= 'border: 1px solid; width: 20px; background-color: $sum%2 == 0? 'pink;':'white;';'</td>"; } echo "</tr>"; } echo "</table>"; ?> I would appreciate if someone can point out my mistakes, thank you so much for reading
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.