0

I want to display the value of two inputs with date type but it didn't work. Here is my code,

    <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel ="stylesheet" href="style_wbr.css"/>
    <title>PORTAIL</title>
</head>
<body>

<br></br>
<br></br>
<br></br>
  <form method = "post" action = "#">
   <div id="date">
  <input type="date" id="date_deb_filtre" name="Date_de_debut" />
  <input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>
</form>
<br></br>


<form method="post" action='#'>
<div class="test">
  <input type="submit" name="test" id="test" value="test"/>
 </div>
  </form>
 <?php

if(isset($_POST['test']))
    {
       if (! empty($_POST['date_deb_filtre']) and (! 
      empty($_POST['date_fin_filtre'])))
         {

      echo ($_POST['Date_de_debut']);
      echo ($_POST['Date_de_fin']);

          }

        }
    ?>


    </body>
   </html>

When I press the test button, the two dates did not appear on the page, can u guys help me with this

4
  • Where's the value attribute of your inputs ? Commented Nov 6, 2017 at 10:25
  • you need to convert id to name or use name attribute value in $_POST Commented Nov 6, 2017 at 10:27
  • @teeyo i addes a value but nothing has changed Commented Nov 6, 2017 at 10:28
  • @WadiBenRhouma your date_deb_filtre and date_fin_filtre are in the wrong form (it doesnt get sent with your test button). Shital's answer fixes it. Commented Nov 6, 2017 at 10:29

4 Answers 4

4

remove extra form tag before test class and use if (!empty($_POST['Date_de_debut']) && !empty($_POST['Date_de_fin'])) in php

<?php
if(isset($_POST['test']))
{
     if (!empty($_POST['Date_de_debut']) && !empty($_POST['Date_de_fin']))
     {

        echo ($_POST['Date_de_debut']);
        echo ($_POST['Date_de_fin']);

      }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel ="stylesheet" href="style_wbr.css"/>
    <title>PORTAIL</title>
</head>
<body>

<br></br>
<br></br>
<br></br>
  <form method = "post" action = "#">
    <div id="date">
      <input type="date" id="date_deb_filtre" name="Date_de_debut" />
      <input type="date" id="date_fin_filtre" name="Date_de_fin" />
    </div>
    <br></br>
    <div class="test">
    <input type="submit" name="test" id="test" value="test"/>
    </div>
  </form>
</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

@Shital Marakana tnks , it worked but what did u mean by "tag"??
both are same && and "and" but if (! empty($_POST['date_deb_filtre']) and (! empty($_POST['date_fin_filtre']))) name is incorrect.
0
  <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel ="stylesheet" href="style_wbr.css"/>
    <title>PORTAIL</title>
</head>
<body>

<br></br>
<br></br>
<br></br>
  <form method = "post" >
   <div id="date">
  <input type="date" id="date_deb_filtre" name="Date_de_debut" />
  <input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>

<div class="test">
  <input type="submit" name="test" id="test" value="test"/>
 </div>
  </form>
 <?php

if(isset($_POST['test']))
    {
       if (!empty($_POST['Date_de_debut']) && (!empty($_POST['Date_de_fin'])))
         {

      echo $_POST['Date_de_debut'];
      echo $_POST['Date_de_fin'];

          }

        }
    ?>


    </body>
   </html>

There are silly mistakes is your code which is like you use two forms for single process and second that you can get value for input field through post method by name not by id.,try using this code this will work.

5 Comments

it works , i want also to add the results of the 'echo' function to an sql query , is it possible ?? and how can i concatenate it??
Yes you can add insert query and assign your $_POST variable in the dedicated field.,it's kind of a rookie question i'll prefer you to search over google you can find your query through that.cheers.
it's not that simple, it's a complicated query with a lot of joins , i tried to excute it bua there's an error of connexction , despite i use the same configuration , and it works in others code, i doubt that there is something wrong with the query
try to run the query in database itself with raw inputs if it works then just copy the query in your code and replace raw data into dynamic variables,
php is only plays role to transfer your query to the database.
0

You are submitting second form in which only this tag exist

<input type="submit" name="test" id="test" value="test"/>

Just remove the second form..

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel ="stylesheet" href="style_wbr.css"/>
        <title>PORTAIL</title>
    </head>
    <body>
        <br></br>
        <br></br>
        <br></br>
        <form method = "post" action = "#">
            <div id="date">
                <input type="date" id="date_deb_filtre" name="Date_de_debut" />
                <input type="date" id="date_fin_filtre" name="Date_de_fin" />
            </div>
            <br></br>
            <div class="test">
                <input type="submit" name="test" id="test" value="test"/>
            </div>
        </form>
    </body>
</html>

Comments

0

Here you should use name attribute instead of id of input tag on if else statement.

Replace this empty($_POST['date_deb_filtre'] , empty($_POST['date_fin_filtre'] with empty($_POST['Date_de_debut'] , empty($_POST['Date_de_fin']

Here is your corect code :

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel ="stylesheet" href="style_wbr.css"/>
    <title>PORTAIL</title>
</head>
<body>
    <br></br>
    <br></br>
    <br></br>
    <form method = "post" action = "#">
        <div id="date">
            <input type="date" id="date_deb_filtre" name="Date_de_debut" />
            <input type="date" id="date_fin_filtre" name="Date_de_fin" />
        </div>
    </form>
    <br></br>
    <form method="post" action='#'>
        <div class="test">
            <input type="submit" name="test" id="test" value="test"/>
        </div>
    </form>
     <?php
        if(isset($_POST['test'])) {
            //echo '<pre>'; print_r($_POST); echo '</pre>'; exit;
            if (! empty($_POST['Date_de_debut']) and (! empty($_POST['Date_de_fin']))) {
                echo ($_POST['Date_de_debut']);
                echo ($_POST['Date_de_fin']);
            }
        }
    ?>
</body>

OR You can Try this:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel ="stylesheet" href="style_wbr.css"/>
    <title>PORTAIL</title>
</head>
<body>
    <br></br>
    <br></br>
    <br></br>
    <form method = "post" action = "#">
    <div id="date">
    <input type="date" id="date_deb_filtre" name="Date_de_debut" />
    <input type="date" id="date_fin_filtre" name="Date_de_fin" />
    </div>
    <div class="test">
    <input type="submit" name="test" id="test" value="test"/>
    </div>
    </form>
    <br></br>
    <?php
        if(isset($_POST['test']))
        {
            //echo '<pre>'; print_r($_POST); echo '</pre>'; exit;
            if (! empty($_POST['Date_de_debut']) and (! empty($_POST['Date_de_fin']))) {
                echo ($_POST['Date_de_debut']);
                echo ($_POST['Date_de_fin']);
            }
        }
    ?>
</body>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.