zafira Posted October 17, 2015 Share Posted October 17, 2015 Make a webpage on which the user can enter his or her name. After the user has clicked on the submit button, a new webpage should appear which welcome him or her with either one of the following messages: "Good morning, [name] !", "Good afternoon, [name] !" or "Good evening, [name] !". The greeting should of course depend on the current time. To read the current hour (in 24 hour format), you can use the following built-in function: date(H). Quote Link to comment https://forums.phpfreaks.com/topic/298653-help-me-to-settle-this-php-question/ Share on other sites More sharing options...
Solution Ch0cu3r Posted October 17, 2015 Solution Share Posted October 17, 2015 I'm not going to give you the code but I will split the question into easy to follow step to achieve the set task. Create a form with an input field for the name. Set the forms action attribute to submit.php (or to the name of your .php file) and set the forms method attribute to post then name the input field name. In the .php file your form submits to use the $_POST['name'] superglobal variable to get the name and assign it to variable, eg $name = $_POST['name']; Assign the suggest date code to a variable, name the variable hour, eg $hour = date('H'); To display the appropriate greeting depending on time of day ( $hour ). You need to use a if/elseif/else statement using the less then or greater than comparison operator(s) for comparing $hour. Example pseudo code if $hour < 12 { echo "Good morning $name" } elseif $hour >= 12 && $hour < 16 { echo "Good afternoon $name" } else { echo "Good Evening $name" } Quote Link to comment https://forums.phpfreaks.com/topic/298653-help-me-to-settle-this-php-question/#findComment-1523523 Share on other sites More sharing options...
zafira Posted October 17, 2015 Author Share Posted October 17, 2015 thank you for helping me... i already run.. but time not display in my web Quote Link to comment https://forums.phpfreaks.com/topic/298653-help-me-to-settle-this-php-question/#findComment-1523524 Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2015 Share Posted October 17, 2015 If you want to diaplay the time on your page use the date function Quote Link to comment https://forums.phpfreaks.com/topic/298653-help-me-to-settle-this-php-question/#findComment-1523526 Share on other sites More sharing options...
zafira Posted October 17, 2015 Author Share Posted October 17, 2015 okey thank you for helping Quote Link to comment https://forums.phpfreaks.com/topic/298653-help-me-to-settle-this-php-question/#findComment-1523530 Share on other sites More sharing options...
benanamen Posted October 17, 2015 Share Posted October 17, 2015 (edited) Forum DO NOT's 10. Do not post your homework to be done. Forum Guidelines 3. Users will not post their homework questions expecting to get their homework coded for them. If you have a question about part of the assignment that you do not understand, please post asking for an explanation rather than the code. Edited October 17, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/298653-help-me-to-settle-this-php-question/#findComment-1523560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.