0

I'm trying to check if the date in the database and today's date is same or not. If yes, then echo a message.

this is the code i'm using

    <?php 

    $date = date("Y - m - d ");
    $matchingdate = $_REQUEST['ending'];

    ?>



 <?php  if ($date == $matchingdate) {

    echo "Yes, Same";
    } else 

    { 

    echo "not same";

    } ?>

How do i insert this if statement within a tag ?

This is what my table looks like

echo "<td>" . $row["name"] . "</td>";
                echo "<td>" . $row["joining"] . "</td>";
                echo "<td>" . $row["ending"] . "</td>"; 

I tried adding like this

Echo "<td>" . if ($date == $matchingdate) {

echo "Yes, Same";
} else 

{ 

echo "not same"; . "</td>"
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Just wrap the `echo "Yes, Same";` with `` in your original `if` statement i.e. `if ($date == $matchingdate) { echo "Yes, Same"; } else { echo "not same"; }` – Nick Mar 25 '20 at 08:02
  • i was able to add the if statement but now i'm getting this error Notice: Undefined index: ending in C:\xampp\htdocs\directory\file2.php on line 5 Line 5 is $matchingdate = $_REQUEST['ending']; – Mohammad Sameer Mar 25 '20 at 08:03
  • You need to check if it's set before you try to use it. – Nick Mar 25 '20 at 08:04
  • You mean whether there is the 'ending' coloumn in mysql database? yes there is the table also shows the ending date section i want to compare if the date in the "ending" section and date today is same then echo the message – Mohammad Sameer Mar 25 '20 at 08:07
  • I don't know why you're using `$_REQUEST`. Your question doesn't have enough detail in it to answer why `$_REQUEST['ending']` might not be set. – Nick Mar 25 '20 at 08:08
  • I have a submit form in backend where admin can post certain persons details including join date and end date to keep data of a person. so i'm using all details including join date and end date rows in mysql. $_REQUEST['ending'] is used to know the end date that the admin put in the backend. so i wanna compare both dates and echo a message – Mohammad Sameer Mar 25 '20 at 09:12

0 Answers0