Page 1 of 1

Search returning empty results

Posted: Sat May 16, 2009 9:23 am
by jstone3503
I am trying to have a simple motor vehicle registration search page where you type in a tag and it returns the basic vehicle information for a school to use. I got everything done but when I search, it returns the table I have made with the headings and so forth, but nothing is being pulled from the database. It's been several years since I've worked with PHP and probably is just one small thing I am missing, but here is my code.

Code: Select all

<?php
$con = mysql_connect("host","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("shb12_041_2", $con);
$sql=("SELECT * FROM mvr WHERE plate = $_POST['plate']");
$result=mysql_query($sql) or die("Error in selecting the database:".mysql_error());
$row=mysql_fetch_row($result);
 
$ownername = $row['ownername'];
$plate = $row['plate'];
$expiration = $row['expiration'];
$address = $row['address'];
$citystatezip = $row['citystatezip'];
$bodytype = $row['bodytype'];
$year = $row['year'];
$make = $row['make'];
$model = $row['model'];
 
echo "<table border=1>";
echo "<tr><td align=top><small>Owner Name</small><br>$ownername</td><td align=top><small>Current Plate</small><br>$plate</td><td align=top><small>Expiration</small><br>$expiration</td><td align=top><small>Address</small><br>$address</td></tr>";
echo "<tr><td align=top><small>City/State/Zip</small><br>$citystatezip</td><td align=top><small>Body Type</small><br>$bodytype</td><td align=top><small>Year</small><br>$year</td><td align=top><small>Make</small><br>$make</td></tr>";
echo "<tr><td align=top><small>Model</small><br>$model</td><td align=top><small>Color</small><br>$color</td><td align=top><small>Stolen</small><br>$stolen</td><td align=top></td></tr>";
 
mysql_close($con);
?> 
 

Re: Search returning empty results

Posted: Sat May 16, 2009 12:22 pm
by ldougherty
try this..

Code: Select all

 
<?php
$con = mysql_connect("host","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("shb12_041_2", $con);
$sql=("SELECT * FROM mvr WHERE plate = $_POST['plate']");
$result=mysql_query($sql) or die("Error in selecting the database:".mysql_error());
 
while ($row = mysql_fetch_array($result)) {
 
 
$ownername = $row['ownername'];
$plate = $row['plate'];
$expiration = $row['expiration'];
$address = $row['address'];
$citystatezip = $row['citystatezip'];
$bodytype = $row['bodytype'];
$year = $row['year'];
$make = $row['make'];
$model = $row['model'];
 
echo "<table border=1>";
echo "<tr><td align=top><small>Owner Name</small><br>$ownername</td><td align=top><small>Current Plate</small><br>$plate</td><td align=top><small>Expiration</small><br>$expiration</td><td align=top><small>Address</small><br>$address</td></tr>";
echo "<tr><td align=top><small>City/State/Zip</small><br>$citystatezip</td><td align=top><small>Body Type</small><br>$bodytype</td><td align=top><small>Year</small><br>$year</td><td align=top><small>Make</small><br>$make</td></tr>";
echo "<tr><td align=top><small>Model</small><br>$model</td><td align=top><small>Color</small><br>$color</td><td align=top><small>Stolen</small><br>$stolen</td><td align=top></td></tr>";
echo "</table>";
echo "<br><br>";
 
}
 
mysql_close($con);
?>
 

Re: Search returning empty results

Posted: Sat May 16, 2009 12:41 pm
by Defiline

Code: Select all

<?php
 
$con = @mysql_connect("host","username","password");
 
if(!$con) {
  die('Could not connect: ' . mysql_error());
}
 
mysql_select_db("shb12_041_2", $con);
 
 
/**
 * Constructing ...
 */
$sql    = "SELECT * FROM `mvr` WHERE `plate` = '".$_POST['plate']."'";
$result = mysql_query($sql);
 
echo '<pre>';
print_r(mysql_fetch_row($result));
 
while($row = mysql_fetch_assoc($result)) {
    
    // While ...
    
}

Re: Search returning empty results

Posted: Sat May 16, 2009 4:53 pm
by jstone3503
I couldn't get ldougherty's code to work but I got the other and wasn't exactly what I was looking for but at least it shows the results. But instead of being in a table it shows up like so:

Array
(
[0] => JOHN DOE
[1] => CA
[2] => ABC123
[3] => 2009-03-31
[4] => 1234 MAIN ST
[5] => BEVERLY HILLS, CA 90210
[6] => SUV
[7] => 2008
[8] => FORD
[9] => MUST
[10] => YEL
[11] => N
[12] =>
)

Is there something else missing that would cause a reason for the table not to be displayed, even though its an array?

Re: Search returning empty results

Posted: Sat May 16, 2009 6:11 pm
by ldougherty
What happens when you run my code? Without the database I can't exactly replicate it but I thought the syntax was on.

If you want to create a dump of your database I'll set it up locally and test it to get it working properly.

Re: Search returning empty results

Posted: Sat May 16, 2009 7:35 pm
by jstone3503
nevermind. i realized it was a mistake on my end. it is working perfect now. thanks for all the help guys.