0

On the form user enter rego no where it search database and display the output what i am looking is, if the entered data not match its should display " Record not found."

<?php

$search_Rego = ($_POST['RegoNo']);

  try 
 {
    //open the database
    $db = new PDO('sqlite:iSearch.sqlite');


    $result = $db->query("SELECT  Fname , Lname , RegoNo, Model, Color, MobNo, DeskNo, AltMobNo
    FROM  Owner
    JOIN Cars ON Owner.id=Cars.Owner_id 
    JOIN Contacts ON Owner.id=Contacts.Owner_id
    where  RegoNo like '$search_Rego'");

{

    foreach($result as $row)
                {
             echo " This Car Belongs to " ; 
              echo "<br />"."<br/>";
             echo $row['Fname']." ". $row['Lname']."<br />"; 
             echo $row[ 'RegoNo']. "<br/>";
             echo $row['Model']." ". $row['Color'].   "<br />" ;
             echo "<br />";
             echo $row['MobNo'].     "<br />" ;
             echo $row['DeskNo'].    "<br />";
             echo $row['AltMobNo'].  "<br />";


                }

   }

    // close the database connection
        $db = NULL;
  }
  catch(PDOException $e)
  {
    print 'Exception : '.$e->getMessage();     

  }

?>

Edited by titos97

2
Contributors
5
Replies
21
Views
4 Years
Discussion Span
Last Post by minitauros
0

Doesn't it work if you just add the following?

if($result)
{
    // Results were found.
    foreach($result as $row)
    {
        echo " This Car Belongs to " ;
        echo "<br />"."<br/>";
        echo $row['Fname']." ". $row['Lname']."<br />";
        echo $row[ 'RegoNo']. "<br/>";
        echo $row['Model']." ". $row['Color']. "<br />" ;
        echo "<br />";
        echo $row['MobNo']. "<br />" ;
        echo $row['DeskNo']. "<br />";
        echo $row['AltMobNo']. "<br />";
    }
}
else
{
    // No results were found.
    echo '<p>No results were found.</p>';
}

Edited by minitauros

0

Hi minitauros thanks for you quick response i tried that not woking when i enter the rego no if the rego no in database it showing the result . but when the data in not in database or not enterd any data it showing blank page not Displaying that record not found.

1

Hm yea for as far as I know the PDO::query() method returns a PDO statement (see also here). I don't know SQLite though. What works for me is this:

try
{
    //open the database
    $db = new PDO('sqlite:iSearch.sqlite');

    $statement = $db->prepare("SELECT Fname , Lname , RegoNo, Model, Color, MobNo, DeskNo, AltMobNo
        FROM Owner
        JOIN Cars ON Owner.id=Cars.Owner_id
        JOIN Contacts ON Owner.id=Contacts.Owner_id
        WHERE RegoNo LIKE :search_rego");
    $statement->bindValue(':search_rego', $search_Rego);
    $statement->execute();
    $result = $statement->fetchAll();

    // close the database connection
    $db = NULL;
}
catch(Exception $e)
{
    echo 'Exception : ' . $e->getMessage();
}

if($result)
{
    // Display results
    foreach($result as $row)
    {
        echo ' This Car Belongs to ';
        echo '<br>' . '<br>';
        echo $row['Fname'] . ' ' . $row['Lname'].'<br>';
        echo $row[ 'RegoNo'] . '<br/>';
        echo $row['Model'] . ' ' . $row['Color']. '<br>' ;
        echo '<br>';
        echo $row['MobNo'] . '<br>' ;
        echo $row['DeskNo'] . '<br>';
        echo $row['AltMobNo'] . '<br>';
    }
}
else
{ 
    // No results were found.
    echo '<p>No results were found.</p>';
}
0

Hey minitauros you are genius . Its working perfectly as i wanted . Great Job . Thanks a lot for your help .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.