Based on the selection of dates how can I display the information stored in database

[quote=“sanruddhirai, post:20, topic:252424, full:true”]

When I manually go and change or set the date it is displaying the information…But for all 31 days to manually change its quite tough…

That code doesn’t relate in any way to the form input that you showed in the first post. You don’t create the variables called $year, $month and $day from that, so of course when you use them in your query, it doesn’t bring anything out because you’re matching it with a string that is “–”.

The first code displays the date as separate drop down list for date,month and year…instead of that code I am now using just which also displays dropdown list…By the way I have removed the first code.

In basic steps (with apologies if this is obvious):

  1. You need a html form, with an input for the date, a submit button, and a destination (the “action” parameter).

  2. Then, in your PHP code (which is in the destination for your for submission), you extract and validate the form variable(s), convert them into a properly-formatted date, and include them in your code.

For point 1, I see that you have a couple of inputs at the top of this code, but you don’t surround them with form tags. Because of that, it’s not a valid HTML form, the browser won’t know what to do when you hit the ‘submit’ button, so even if it draws the date input it won’t be doing anything with it. You don’t specify a name parameter for your date input field, so there’s no way to process it once the destination code is running, or even if the browser somehow defaults to reloading the same code when you hit submit.

For point 2, you don’t extract the values from the form variables, even if they were coming through properly with a name and so on. You create a variable called $date as today’s date, but don’t do anything with it.

So my first suggestion would be to read up on HTML forms, then create yourself a HTML page with a properly coded form, and a brief destination PHP page that extracts the form variables and displays them. Once you’ve done that, it’ll be really easy to take those variables, and insert them into your query.

I will start again from the begining…If doubt arises I will ask it here…Thanks.

This displays the 1st form…where the user makes the entries and these will be saved in database

<html>
<head></head>
<body>
 welcome to the page<br/>

<form action="connect.php" method="post">
<?php 
$date = date(" Y-m-d"); 
echo "$date";
?>
Name:<input type="text" name="Name">
Action:<select name="Action">
<option value="Roy">Roy</option>
<option value="Smith">Smith</option>
<option value="VK">VK</option>
 </select>
Fruits<select name="Fruits" >
<option  value="Orange">performance</option>
<option  value="Mango">malware</option>
<option  value="Apple">spamming</option>
<option  value="Banana">mysql abuser</option>
</select>
Batchnumber:<input type="text" name="Batchnumber">
 <input type="submit" value="submit"/>
</form>
</body>
</html>
 
 This is where the connection database code is present

<?php
$con = mysql_connect('dbservername','dbuser','dbpassword');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db('dbname');

$date = date(" Y-m-d"); 
 
$sql="INSERT INTO details (date,Name, Fruits,Batchnumber)
VALUES
('$date','$_POST[Name]','$_POST[Fruits]','$_POST[Batchnumber]')";
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>
 This is another form where on submission of date I WANT TO DISPLAY THE INFORMATION THAT IS STORED IN DATABASE OR LIKE HOW MANY RECORDS WERE ADDED ON THAT PARTICULAR DAY.
 <html>
<head>
<body><br>

date:<input type="date" value=" ">
<input type="submit" value="submit"/>
<?php
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$date = date(" Y-m-d"); 
echo "$date <br>";

if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = "SELECT date,Fruits FROM details WHERE Fruits = 'Orange' and date= '2017-01-20'  ";


mysql_select_db('information');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_NUM))
{
    echo  "comments: {$row[1]} <br> ".
       "date {$row[0]} <br>".
         "--------------------------------<br>";
}mysql_free_result($retval);
echo "Fetched data successfully\n";
mysql_close($conn);
?>
</body>
</html>
...................................
THE SAME ABOVE CODE I HAVE WRITTEN IN SOME OTHER FORMAT THINKING ATLEAT THAT WOULD WORK
<html>
<head>
<body>
<?php 
$thedate = date("d F Y"); 
echo "$thedate";
?>

date:<input type="date" value=" ">
<input type="submit" value="submit">
Orange:<input type="text" name= " <?php echo $previous_Orange_count; ?>"
Mango:<input type="text" name= " " ?php echo $_POST[""]; ? >
Apple:<input type="text" name= " "?php echo $_POST[""]; ? > 
Banana :<input type="text" name= " " ?php echo $_POST[""]; ? >
Count:<input type="text" name= " " >
</body>
</html>

This displays the 1st form…where the user makes the entries and these will be saved in database

<html>
<head></head>
<body>
 welcome to the page<br/>

<form action="connect.php" method="post">
<?php 
$date = date(" Y-m-d"); 
echo "$date";
?>
Name:<input type="text" name="Name">
Action:<select name="Action">
<option value="Roy">Roy</option>
<option value="Smith">Smith</option>
<option value="VK">VK</option>
 </select>
Fruits<select name="Fruits" >
<option  value="Orange">performance</option>
<option  value="Mango">malware</option>
<option  value="Apple">spamming</option>
<option  value="Banana">mysql abuser</option>
</select>
Batchnumber:<input type="text" name="Batchnumber">
 <input type="submit" value="submit"/>
</form>
</body>
</html>

This is where the connection database code is present

<?php
$con = mysql_connect('dbservername','dbuser','dbpassword');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db('dbname');

$date = date(" Y-m-d"); 
 
$sql="INSERT INTO details (date,Name, Fruits,Batchnumber)
VALUES
('$date','$_POST[Name]','$_POST[Fruits]','$_POST[Batchnumber]')";
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>

This is another form where on submission of date I WANT TO DISPLAY THE INFORMATION THAT IS STORED IN DATABASE OR LIKE HOW MANY RECORDS WERE ADDED ON THAT PARTICULAR DAY.

 <html>
<head>
<body><br>

date:<input type="date" value=" ">
<input type="submit" value="submit"/>
<?php
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$date = date(" Y-m-d"); 
echo "$date <br>";

if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = "SELECT date,Fruits FROM details WHERE Fruits = 'Orange' and date= '2017-01-20'  ";


mysql_select_db('information');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_NUM))
{
    echo  "comments: {$row[1]} <br> ".
       "date {$row[0]} <br>".
         "--------------------------------<br>";
}mysql_free_result($retval);
echo "Fetched data successfully\n";
mysql_close($conn);
?>
</body>
</html>


THE SAME ABOVE CODE I HAVE WRITTEN IN SOME OTHER FORMAT THINKING ATLEAT THAT WOULD WORK

<html>
<head>
<body>
<?php 
$thedate = date("d F Y"); 
echo "$thedate";
?>

date:<input type="date" value=" ">
<input type="submit" value="submit">
Orange:<input type="text" name= " <?php echo $previous_Orange_count; ?>"
Mango:<input type="text" name= " " ?php echo $_POST[""]; ? >
Apple:<input type="text" name= " "?php echo $_POST[""]; ? > 
Banana :<input type="text" name= " " ?php echo $_POST[""]; ? >
Count:<input type="text" name= " " >
</body>
</html>

Going back to what I was saying earlier on, you need to look at the html of the form and get that correct before you go anywhere further. If you look at the first piece of code in your latest post, you have a properly-formatted html form, surrounded by form tags, with an action parameter. In your last two examples, neither have a proper form nor any action to tell the browser what to do when you submit the form. So, take the third section of code (which looks exactly the same as the code you posted in #26), get rid of all the PHP for running the query because that isn’t the correct place for it, and turn that into a working form, first of all. Then take the PHP code, stick it in a separate file (the name of that file goes in the action parameter in your form tag) and go from there.

As I said earlier, break it down into steps, and get each step working, before you go on to the next step. You’ve got an example in your first form that allows you to post into the database.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.