...

View Full Version : Echo problem please help my deadline is today



doleary22
11-18-2010, 12:34 PM
I am supposed to make a gui for a fictitious car company that holds the data in tables in a mysql database. The code has 5 drop down menus for make model color year and mileage. The code is supposed to read the selections of the user on the drop down menus and then filter the information in the database to match the request by the user. Then it is supposed to echo the results to the user. It is supposed to work similar to cars.com. However, when I click the submit button, instead of echoing the results, all it says is "connected to mysql server." How do i alter my code to echo the results to the user



<?php

if(isset($_POST['Make'])) {



$Make = $_POST['Make'];



$Model = $_POST['Model'];



$Year = $_POST['Year'];



$Mileage = $_POST['Maximum_Mileage'];



$Color = $_POST['Color'];

$Price = $_POST['Price'];


$dbhost = "xxx"; //host



$dbuser = "xxx"; //username



$dbpass = "xxx"; //password



$dbname = "xxx"; // database name



$dbconnection=mysqli_connect($dbhost, $dbuser, $dbpass) or die(mysqli_connect());



$db_selected=mysqli_select_db($dbconnection, $dbname);



echo "connected to MySQL <br/>";



$Query=("SELECT * FROM Inventory WHERE Make = '$Make' AND Model = '$Model' AND Year = '$Year' AND Mileage = '$Mileage' AND Color = '$Color'") or die (mysql_error());


$result = mysqli_query($dbconnection,$Query) or die (mysqli_error($dbconnection));
while ($row = mysqli_fetch_array($result)) {






echo "<br />";






echo $row['Make']. "-". $row['Model']. "-".






$row['Year']. "-". $row['Mileage']. "-".






$row['Color'];






echo "<br/>";



}
} else {
?>

<html>
<head>
<title>Some Title</title>
<style type="text/css">
table{margin-left:0%;margin_right:0%;width:100%}
td{font-size:36;color:Black;background-color:tan; text-align:center;border: 4px solid black;}
th{font-size:18;color:Black;background-color:gray;text-align:center;border: 4px solid black;}
</style>

<form method="POST" action="some_action.php">
<table border>
<tr>
<td colspan="13"> Column Title </td>
</tr>

<tr>
<th>Make</th><th><select name="Make">
<option value="Ford">Ford</option>
<option value="Mercury">Mercury</option>
<option value="Mazda">Mazda</option>
<option value="Subaru">Subaru</option>
<option value="Toyota">Toyota</option></select>

<th>Model</th><th><select name="Model">
<option value="Accord">Accord</option>
<option value="Taurus">Taurus</option>
<option value="Millenia">Millenia</option>
<option value="Forester">Forester</option>
<option value="Sable">Sable</option>
<option value="Focus">Focus</option>
<option value="Tracer">Tracer</option>
<option value="Outback">Outback</option>
<option value="Ranger">Ranger</option>
<option value="Camry">Camry</option>
<option value="Mountaineer">Mountaineer</option>
<option value="Legacy">Legacy</option>
<option value="Miata">Miata</option>
<option value="Explorer">Explorer</option>
<option value="Cougar">Cougar</option>
<option value="Civic">Civic</option>
<option value="Protege">Protege</option>
<option value="Impreza">Impreza</option>
<option value="Mustang">Mustang</option>
<option value="Expedition">Sable</option>
<option value="Villager">Villager</option>
<option value="Grand Marqui">Grand Marqui</option>
<option value="Winstar">Winstar</option>
<option value="F-150">F-150</option>
<option value="Sable">Sable</option></select>

<th>Year</th><th><select name="Year">
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option></select>

<th>Maximum Mileage</th><th><select name="Maximum_Mileage">
<option value="10,000+">10,000+</option>
<option value="20,000+">20,000+</option>
<option value="30,000+">30,000+</option>
<option value="40,000+">40,000+</option>
<option value="50,000+">50,000+</option>
<option value="60,000+">60,000+</option>
<option value="70,000+">70,000+</option>
<option value="80,000+">80,000+</option>
<option value="90,000+">90,000+</option>
<option value="100,000+">100,000+</option></select>

<th>Color</th><th><select name="Color">
<option value="Blue">Blue</option>
<option value="Yellow">Yellow</option>
<option value="Silver">Silver</option>
<option value="Gold">Gold</option>
<option value="Red">Red</option>
<option value="Purple">Purple</option>
<option value="Green">Green</option>
<option value="Forrest Green">Forrest Green</option>
<option value="Teal">Teal</option>
<option value="Navy">Navy</option>
<option value="Maroon">Maroon</option></select>
</th>

<th>Price</th><th><select name = "Price">
<option value="2,000+">2,000+</option>
<option value="4,000+">4,000+</option>
<option value="6,000+">6,000+</option>
<option value="8,000+">8,000+</option>
<option value="10,000+">10,000+</option>
<option value="12,000+">12,000+</option>
<option value="14,000+">14,000+</option>
<option value="16,000+">16,000+</option>
<option value="18,000+">18,000+</option>
<option value="20,000+">20,000+</option>
<option value="22,000+">22,000+</option>
<option value="24,000+">24,000+</option>
</tr>
<tr><th colspan="13" align=center><input type="submit" name="s" value="Submit"</th></tr>


</table>
</form>
</head>
</html>

<?
}

mlseim
11-18-2010, 02:41 PM
I think you're getting a script error and so it halts.

This line doesn't look right ...

$Query=("SELECT * FROM Inventory WHERE Make = '$Make' AND Model = '$Model' AND Year = '$Year' AND Mileage = '$Mileage' AND Color = '$Color'") or die (mysql_error());

It should be more like this ...

$Query="SELECT * FROM Inventory WHERE Make = '$Make' AND Model = '$Model' AND Year = '$Year' AND Mileage = '$Mileage' AND Color = '$Color'";


If nothing still shows up, that means you found no rows that matched the query.



.

tjfoz
11-18-2010, 09:22 PM
doleary, try adding



$Query=("SELECT * FROM Inventory WHERE Make = '$Make' AND Model = '$Model' AND Year = '$Year' AND Mileage = '$Mileage' AND Color = '$Color'") or die (mysql_error());

echo $Query . "<br>";

$result = mysqli_query($dbconnection,$Query) or die (mysqli_error($dbconnection));
while ($row = mysqli_fetch_array($result)) {


Then run the query directly in the database and make sure you are getting a result. Good luck!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum