I have a HTML form Having two fields From: and To: both are text fields(to genereate a report).I want to use these data to query on two tables based on the date specified(DD-MM-YYYY) i.e from and to and using these to select values from the two tables visitor_in and visitor_out each having same no. of fields except visitor_in has Time_In and other visitor_out has Time_Out.
Here's my code:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("entry", $con);  //entry is the database


$from=$_POST['from']; //values from
$to=$_POST['to'];     //text fields of HTML form      

// Construct our join query
$result = mysql_query("SELECT visitor_in.Name,visitor_in.Contact_Number,visitor_in.Date,visitor_in.Time_In,visitor_out.Time_Out FROM visitor_in,visitor_out WHERE visitor_in.Date BETWEEN '$from' AND '$to' ") or die(mysql_error());
 
//Printing as a HTML table
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Contact Number</th>
<th>Date</th>
<th>Time In</th>
<th>Time Out</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['visitor_in.Name'] . "</td>";
  echo "<td>" . $row['visitor_in.Contact_Number'] . "</td>";
  echo "<td>" . $row['visitor_in.Date'] . "</td>";
  echo "<td>" . $row['visitor_in.Time_In'] . "</td>";
  echo "<td>" . $row['visitor_out.Time_Out'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

After I input form field with date(DD-MM-YYYY) no result is yielded only the table headings Name contact number date time in time out appear but not the rows to be selected. Im using WAMP server.

Have you displayed dates to see if Form dates format matches the Database stored dates?

Have you displayed dates to see if Form dates format matches the Database stored dates?

Yes I always Make sure to input date from the user In the format (DD-MM-YYYY) i always write it next to the input field.

I have the Date field in both the table as TEXTfield for compatibility with the input field instead of Date type could that be a problem?

try echo the query and pase what it displays
also you can try this

$result = mysql_query("SELECT visitor_in.Name,visitor_in.Contact_Number,visitor_in.Date,visitor_in.Time_In,visitor_out.Time_Out FROM visitor_in,visitor_out WHERE visitor_in.Date BETWEEN '".$from."'AND '".$to."' ") or die(mysql_error());"

try echo the query and pase what it displays
also you can try this

$result = mysql_query("SELECT visitor_in.Name,visitor_in.Contact_Number,visitor_in.Date,visitor_in.Time_In,visitor_out.Time_Out FROM visitor_in,visitor_out WHERE visitor_in.Date BETWEEN '".$from."'AND '".$to."' ") or die(mysql_error());"

I tirwd what you wrote but gave me following error:

Notice: Undefined index: from in C:\wamp\www\vm\report.php on line 11

Notice: Undefined index: to in C:\wamp\www\vm\report.php on line 12

what are contents of lines 11 and 12?
Can you echo the values of $from and $to?

what are contents of lines 11 and 12?
Can you echo the values of $from and $to?

Sorry that didnt help!!1 Can you tell general method take any example ofyours explaining the use of form variables and then using that data to query on two table simultaneusly.
Maybe it will help.

Test this in your app
index.html

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <form name="myform" action="test.php" method="POST">
              <p>Time In<input name="in_time" type="text" /></p>
              <p>Time Out<input name="out_time" type="text" /></p>
              <input name="Submit" type="submit" />
        </form>
</body>
</html>

test.php

<?php

$in = $_POST['in_time'];
$out = $_POST['out_time'];
echo "Out Time is $out<br />";
echo "You Got in at $in";

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.