Page 1 of 1

Need Help please!!!!

Posted: Thu Aug 12, 2010 8:03 am
by Prerit
[text]Can Anyone tell me whats wrong with the following code?? Im using Wampserver[/text] for all PHP and mySQl

Code: Select all

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

mysql_select_db("check_in", $con);
mysql_select_db("check_out", $con);

$from=$_POST['from'];
$to=$_POST['to'];
// Construct our join query

$result = mysql_query("SELECT visitor1.Name,visitor1.Contact_Number,visitor1.Date,visitor1.Time_In,visitor2.Time_Out FROM visitor1,visitor2 WHERE visitor1.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['Name'] . "</td>";
  echo "<td>" . $row['Contact_Number'] . "</td>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['Time_In'] . "</td>";
  echo "<td>" . $row['Time_Out'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?> 
The above form basically takes two text Date Fields (To: and From:) from a HTML form(file attached) and searches it the following two databases:

Database name: check_in
tables: visitor 1
fields: Name , Contact_Number ,Date,Time_In

Database name: check_out
tables: visitor 2
fields: Name , Contact_Number ,Date,Time_Out


Here is my HTML coding I couldnt attach becuase .html file cannot be uploaded
<html>
<head>
<title>report</title>
</head>

<body>
<br><br>
<pre>
<form action="abc.php" method="post">

From: <input type="text" Size="30" MAXLENGTH="10" Value="" name="from"/> To: <input type="text" Size="30" MAXLENGTH="10" Value="" name="to"/>
<input type="submit" value="Submit"/>
</pre>
</form>
</body>
</html>


Thanks in advance for the Help!!!! :lol: :lol: :lol: :lol: :lol: :roll: :roll: :roll: :roll: :roll: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :drunk: :drunk: :drunk: :drunk: :drunk: :drunk:

Re: Need Help please!!!!

Posted: Thu Aug 12, 2010 11:42 am
by Jsphlane20
Please provide a little more information. Are you receiving any php errors of any kind ? Every little bit helps in troubleshooting.

Re: Need Help please!!!!

Posted: Thu Aug 12, 2010 12:49 pm
by Prerit
Yes, I am getting the error check_out visitor1 is not available.
Basically I want to query on two different tables form two diff databases. Basically what i want to do is :

[text]1.Accept To and From (Both text fields) from HTML form .These are used to find records from 'x' date to 'y' date.
2.Retrive records from tow databases check_in and check_out on the basis of dates mentioned by user
3.Display result in HTML Table form[/text]


Banging my head :banghead: :banghead: :banghead: :banghead: cant solve this, need real help!!!
P.S Im new to PHP and mySQl

Re: Need Help please!!!!

Posted: Thu Aug 12, 2010 1:12 pm
by mikosiko
Why you need 2 databases? ... curious

if you do this modifications... what do you get?

Code: Select all

mysql_select_db("check_in", $con)  or die(mysql_error());
mysql_select_db("check_out", $con)  or die(mysql_error());