I have written an SQL statement which works in phpmyadmin. I have two databases on the same server which I have used an INNERJOIN to connect them and im getting the correct results. I am building this up in php and so far have done a few normal queries and got the correct results. I have an include for my db, which is connecting to one database, now I want to connect to two and im not sure how I reference this in in my php sql statement. Can someone please help.
I have this.
<?php
error_reporting(0);
include './includes/opendb.php';
extract($_POST);
$sql1 = mysql_query("SELECT f_clients.CLIENT_COMPANY, vtmastertrail.consultant, f_clients.CLIENT_CODE, vtcards.description, vtmastertrail.inspdate_start, vtmastertrail.inspdate_end, vtcards.typeofcard, vtcards.colour, vtcards.frequency, vtcards.priorityon, vtmastertrail.islive, f_clients.CLIENT_DEFAULTINSPECTIONSELL
FROM `f_clients`
INNER JOIN tcards.vtcards ON tcards.vtcards.client_code = f_clients.CLIENT_CODE
INNER JOIN tcards.vtmastertrail ON tcards.vtmastertrail.card_id = tcards.vtcards.id
WHERE tcards.vtmastertrail.consultant = '".$con_name."'
AND tcards.vtmastertrail.inspdate_start >= '".$from_date."'
AND tcards.vtmastertrail.inspdate_start <= '".$to_date."'");
echo "<table border='1' align='center'>
<tr>
<th>Consultant</th>
<th>Client Code</th>
<th>Client</th>
<th>Address</th>
<th>Inspection Start Date</th>
<th>Inspection End Date</th>
<th>Type Of T-Card</th>
<th>T-Card Colour</th>
<th>Frequency</th>
<th>Priority</th>
<th>Report Sent Out</th>
<th>Cost</th>
</tr>";
while($row = mysql_fetch_array($sql1))
{
echo "<tr>";
echo "<td>" . $row['consultant'] . "</td>";
echo "<td>" . $row['client_code'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['inspdate_start'] . "</td>";
echo "<td>" . $row['inspdate_end'] . "</td>";
echo "<td>" . $row['typeofcard'] . "</td>";
echo "<td>" . $row['colour'] . "</td>";
echo "<td>" . $row['frequency'] . "</td>";
echo "<td>" . ($row['priorityon'] ? 'Yes' : 'No') . "</td>";
echo "<td>" . ($row['signedoff'] ? 'Yes' : 'No') . "</td>";
echo "<td>" . $row['CLIENT_DEFAULTINSPECTIONSELL'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
Im basically getting no results from this search.
here is my db file.
<?php
// ** database connection string
$conn = mysql_connect("localhost", "#####", "########") or die ('I cannot connect to the database because: ' . mysql_error());
// ** Tcards database
mysql_select_db ("tcards");
Ive changed hidden the credentials. I have another database called 'test' which is where the f_clients table is. This is on the same server and has the same login credentials. Can anyone help me out please?
extract($_POST);ever. This is the equivalent to "register globals" which was removed from PHP due to it being a huge security risk. Also, you should never put any data into an SQL query without being properly escaped.$POSTvar directly, and instead of putting the values into the SQL query the way you are, use prepare statements. Take a look at this tutorial: markonphp.com/mysqli-select-prepared-statements