Hello, I need help with my code. Can somebody take a look at my code... What I want to do is when user select the checkbox, the script execute and print Sunday. If not selected the script will print Not Sunday. This is the form code. I only use 1 checkbox. <form> Tell me day:<input type="checkbox" value="sunday" name="day"><?php echo $_GET['day'];?> </form> PHP: the php form code $day = $_POST["day"]; foreach ($day as 1) if ( $day == 1 ) { echo "Sunday"; } else { echo "Not Sunday"; } PHP: I think my php form code has error in it. I don't know becuase I'm not very good with php. Please help. Thanks in advance
not sure what you are trying to do but this will echo sunday : <form method=post action="test.php"> <input type="checkbox" value="sunday" name="day"> <input type="submit"> </form> <? $day = $_POST["day"]; echo "<BR>day = $day<BR>"; if($day) echo "Sunday"; else echo "Not Sunday"; ?>
EDIT: Beaten to the answer! But anyway, bug correction, while still echoing sunday when it is sunday, and not sunday when it isn't... <?php $day = $_POST["day"]; if (strtolower($day) == 'sunday') {// loop removed because unnecessary, and this if statement made to mean something echo "Sunday"; } else { echo "Not Sunday"; } ?> PHP: