Jump to content

search string in data base


maideen
Go to solution Solved by maideen,

Recommended Posts

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

 

<?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"  /> </td>
    <td><input type="submit" name="submit" id="search" value="Search" /></td>
</form>
</body>
</html>

Search.php

<?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->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

 

 

 

Link to comment
Share on other sites

  • Solution

hi

Thank you of you to give the suggestion to solve the problem.

there was wrong in Search.php

Here is the code working fine

 

<?php
    $query = $_GET['query'];
    echo $query;

    $stmt = $dbh->query("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%' OR Address LIKE '%".$query."%')");
    $stmt->setFetchMode(PDO::FETCH_ASSOC); 



    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'];  
      
        }
        }?> 

Thank you very much once again

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.