If $ _POST is an empty function

I create a form where I use the php function $ _POST.

This is what my form looks like.

form.php

<h1>Songs Movies Form</h1> <hr /> <form action="songs-movies.php" method="post"> Song Name: Enter Song Name: <input type="text" name="SongName" size="25" /> Enter Movie Name: <input type="text" name="MovieName" size="25" /> <input type="submit" value="Submit" name="submit" /> </form> <br /> <a href="/forms/">Back to Forms</a> <hr /> 

Now I want to display the result of SongName and MovieName , so I used echo $ _POST ["SongName"]; and echo $ _POST ["MovieName"]; which perfectly generates the result.

Now I want to put these SongName and MovieName values between the text / line / pairs on the result / output page, and if the SongName or MovieName value is empty, then the result / result should not display this text / line / pair where I put these functions.

eg.


ABC Song is a popular XYZ Movie song. XYZ's ABC Song film is managed by the PQR Director.


Now you can see that in the paragraph above there are two sentences. I want to put a function for the first sentence only when the values โ€‹โ€‹of the SongName and MovieName fields are empty, and then

  • The first sentence should display whether the SongName and MovieName fields are empty or not. Those. ABC Song is a popular XYZ Movie song. If the values โ€‹โ€‹of the SongName and MovieName fields are empty, then it can leave a space between them, and I know that this can be done using this function echo $ _POST [SongName "] ;.

BUT

  • It should not display the first line of the sentence if the values โ€‹โ€‹of the SongName field and the movie name are empty, i.e. ABC Song of XYZ Movie is managed by the director of PQR.
+4
source share
3 answers

I think what you are looking for is something like:

 if(!empty($_POST['foo'])) { echo "a sentence".$_POST['foo']." with something in the middle."; } 

This will verify that the value is NOT empty, however many things are empty in PHP, so you may need to be more specific. For example, you can check simple if its set:

 if(isset($_POST['foo'])) { echo "a sentence".$_POST['foo']." with something in the middle."; } 
+11
source

You really embarrassed me with the last 2-3 sentences.
What you want to do can be done using if, elseif, and other control structures.

 if ($_POST['MovieName'] AND $_POST['SongName']) { //code } elseif ($_POST['MovieName']) { //code } elseif ($_POST['SongName']) { //code } else { //code } 
+2
source

You can do this in three ways.

  •  if(isset($_POST['value1'])) { //... } 
  •  if(!empty($_POST['value1'])) { //... } 
  • and easy way

     if($_POST('value1')=="") { .... } 

I sometimes use the third method, when they confuse me with submitting forms, but, of course, the first and second are more elegant!

0
source

All Articles