Jump to content

help me to settle this php question


Go to solution Solved by Ch0cu3r,

Recommended Posts

  1. 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).

Link to comment
https://forums.phpfreaks.com/topic/298653-help-me-to-settle-this-php-question/
Share on other sites

  • Solution

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"
    }
    

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 by benanamen
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.