Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have one problem , I need to search any string data . Below my code. When I click, no results as well as no error

Index.php
XML
<?php  include_once '../templete/header.php'; ?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="search.php" method="get" >
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><input type="text" name="query" id="text"  />&nbsp;</td>
    <td><input type="submit" name="submit" id="search" value="Search" /></td>
</form>
</body>
</html>

Search.php


XML
<?php
 include_once '../templete/header.php';
 include_once '../inc/connection.inc.php';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table>
<tr>
  <td>Name</td>
  <td>Address</td>
  </tr>
<?php
    $query = $_GET['query'];

    //$stmt = $dbh->prepare("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%') OR (Address LIKE '%".$query."%')");
    $stmt = $dbh->prepare("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%' OR Address LIKE '%".$query."%')");
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    //$stmt->execute();
    if(isset($stmt))
        {
            while($row = $stmt->fetch()); ?>
              <tr>
              <td><?php echo $row['Name'];?></td>
              <td><?php echo $row['Address'];?></td>
              </tr>
        <?php
        }
?>
</table>
</body>
</html>


Pls Help me

Maideen
Posted

1 solution

Hi

I have solved this issue. There was error in Search.php

Here is the code which is work fine..

XML
<?php
    $query = $_GET['query'];
    echo $query;
    //$stmt = $dbh->prepare("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%') OR (Address LIKE '%".$query."%')");
    $stmt = $dbh->query("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%' OR Address LIKE '%".$query."%')");
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    //$stmt->execute();

    if(isset($stmt))
        {
            while($row = $stmt->fetch()){ ?>
              <tr>
              <td><?php echo $row['Name'];?></td>
              <td><?php echo $row['Address'];?></td>
              </tr>
        <?php

        echo $row['Name'];

        }
        }
?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900