PHP Program to find weekday – simple with form and with database
Simple PHP Program to find weekday
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <!DOCTYPE html> <html> <body bgcolor="yellow"> <center> <br></br> <br> <br> <?php $days = "5"; echo 'The Number is '; echo $days; switch ($days) { case "1": echo " and its MONDAY!"; break; case "2": echo " and its TUESDAY!"; break; case "3": echo " and its WEDNESDAY!"; break; case "4": echo "and its THURSDAY!"; break; case "5": echo "and its FRIDAY!"; break; case "6": echo "and its SATURDAY!"; break; case "7": echo "and its SUNDAY!"; break; default: echo "there is no other day :) !"; } ?> </center> </body> </html> |
Output
The number is 5 and its FRIDAY!
PHP Program to find weekday with form
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <html> <body bgcolor=" pink"> <center> <br> <br> <form method="post"> Enter a number (1 - 7):<br> <input name="dayname" type="number" maxlength="100" /> <br> <input type="submit" name="submit" value="Check it!"> </form> <?php if(isset($_POST['submit'])) { $num=($_POST["dayname"]); $common="you select"; switch ($num) { case '1': echo "$common $num, it's MONDAY."; break; case '2': echo "$common $num, it's TUESDAY."; break; case '3': echo "$common $num, it's WEDNESDAY."; break; case '4': echo "$common $num, it's THURSDAY."; break; case '5': echo "$common $num, it's FRIDAY."; break; case '6': echo "$common $num, it's SATURDAY."; break; case '7': echo "$common $num, it's SUNDAY."; break; default: echo "there is no other day :)"; } } ?> </body> </center> </html> |
PHP Program to find weekday with database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | <html> <body bgcolor=" pink"> <center> <br> <br> <?php $dbServername = "localhost"; $dbUsername = "root"; $dbPassword = ""; $dbName ="T4Tutorials"; // Create connection $conn= mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected To database successfully <br><br>"; ?> <form method="post"> Enter a number (1 - 7):<br> <input name="dayname" type="number" maxlength="100" /> <br> <input type="submit" name="submit" value="Check it!"> </form> <?php if(isset($_POST['submit'])) { $num=($_POST["dayname"]); switch ($num){ case '1': $name=" MONDAY."; echo $name; break; case '2': $name = " TUESDAY."; echo $name; break; case '3': $name = " WEDNESDAY."; echo $name; break; case '4': $name = " THURSDAY."; echo $name; break; case '5': $name = " FRIDAY."; echo $name; break; case '6': $name = " SATURDAY."; echo $name; break; case '7': $name = " SUNDAY."; echo $name; break; default: $name = "NO day :)"; echo $name; } $sql="INSERT INTO `noortbl` (`id`, `num`, `day`) VALUES (NULL, '$num','$name')"; if ($conn->query($sql) === TRUE) { echo "<br> Record Added successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } ?> </body> </center> </html> |