-2

I am working on my web project and i am trying to make a search bar using php and MySql data base.But every time I get above Warning message and I have tried almost every solution on Stack Overflow.

But any of that wont give me any improvement.In my database there is a table named 'project_2013' and it has 4 columns 'ID,NAME,PROJECT,TITLE'.This is the php code I have used.

    <?php
    if(isset($_POST['search'])){
        $searchTerm = $_POST['search'];
'%$searchTerm%'";
        $query = "SELECT * FORM project_2013 WHERE TITLE LIKE 
'%".mysqli_real_escape_string($con, $searchTerm)."%'";
        $result = mysqli_query($con,$query);
        $count = mysqli_num_rows($result);
        if ($count == 0){
            echo 'SORRY Nothing in our Server...';
        }
        else{
             while($row = mysqli_fetch_array($query)){
               $title = $row['TITLE'];
               $projectName = $row['PROJECT'];
               $name = $row['NAME'];
               echo '<br>';
               echo '<div class = "row">';//row start
               echo '<div id = "content" class = "col-lg-12 col-md-12 col-sm-12 col-xs-12">'; //div1
               echo '<b>Title:</b> ' .  $row['TITLE'] . '<br>';
               echo '<b>Research Paper:</b> ' . '<a href = "documents/2013_2014/' . $row['PROJECT'] .'" target = "_blank">'. $row['TITLE']  . '</a>' . '<br>';
              echo '<b>Conducted By:</b> ' . $row['NAME'] . '<br>';
              echo '</div>';//end of div1  
              echo '</div>';//row end
              echo '<hr>';
            }
        }
    }?>

This is the form tag part.

<form action = "Home.php" method = "post">
    <div class="input-group">
    <input type="text" class="form-control" name = "search" placeholder="Search for Research...">
    <span class="input-group-btn">
    <button class="btn btn-default" type="submit" name="submit">
    <span class="glyphicon glyphicon-search"></span></button>
    </span>
    </div><!-- /input-group -->

Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51
user7670190
  • 5
  • 1
  • 5
  • Possible duplicate of [mysqli\_fetch\_array()/mysqli\_fetch\_assoc()/mysqli\_fetch\_row() expects parameter 1 to be resource or mysqli\_result, boolean given](https://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc-mysqli-fetch-row-expects-parameter-1) – Carl Binalla Jun 30 '17 at 05:55
  • 1
    Check the SQL - `SELECT * FORM` should probably be `SELECT * FROM`. – Nigel Ren Jun 30 '17 at 05:56
  • did your query is working properly? – Pranav MS Jun 30 '17 at 05:58

2 Answers2

0

Use :

"SELECT * FROM"

In SQL instead of :

"SELECT * FORM

Note :

You should verify SQL before adding it into code.

Code with Syntax problems should not be posted here.

LuFFy
  • 8,799
  • 10
  • 41
  • 59
0

First u should change "SELECT * FROM" in that query section.

section and one more think u should change mysqli_fetch_array($query) instead of mysqli_fetch_array($result) .

check the below the correct code

<?php
if(isset($_POST['search'])){
    $searchTerm = $_POST['search'];
    //$searchTerm = preg_replace("#[^0-9 a-z]#i","",$searchTerm);
    //$query = "SELECT * FROM project_2013 WHERE TITLE LIKE '%$searchTerm%'";
    $query = "SELECT * FORM project_2013 WHERE TITLE LIKE '%".mysqli_real_escape_string($con, $searchTerm)."%'";
    $result = mysqli_query($con,$query);
    $count = mysqli_num_rows($result);
    if ($count == 0){
        echo 'SORRY Nothing in our Server...';
    }
    else{
            while($row = mysqli_fetch_array($result)){
                $title = $row['TITLE'];
                $projectName = $row['PROJECT'];
                $name = $row['NAME'];

                echo '<br>';
                echo '<div class = "row">';//row start
                    echo '<div id = "content" class = "col-lg-12 col-md-12 col-sm-12 col-xs-12">'; //div1
                        echo '<b>Title:</b> ' .  $row['TITLE'] . '<br>';
                        echo '<b>Research Paper:</b> ' . '<a href = "documents/2013_2014/' . $row['PROJECT'] .'" target = "_blank">'. $row['TITLE']  . '</a>' . '<br>';
                        echo '<b>Conducted By:</b> ' . $row['NAME'] . '<br>';
                    echo '</div>';//end of div1  
                echo '</div>';//row end
                echo '<hr>';
        }
    }
}?>
Community
  • 1
  • 1
Prabu T
  • 27
  • 3