1

can u tell me whats wrong? i want to ouput "yes" if match is found and "No Result" result if there is no result.. it seems that it dont ouput anything..

    <?php
        $output = NULL;

        if(isset($_POST['submit'])){
            $st = $_POST['search'];
            //Connect to the Database
            $mysqli =NEW mysqli("localhost","root","","exam");

            $search = $mysqli->real_escape_string($st);
            echo $st;

            //Query Database
            $result = $mysqli->query("SELECT * FROM users WHERE name = '$search'");
            if($result->num_rows > 0){
                echo "yes";
            }
        else{
            echo "No RESULT";
        }
    }

?>
<form>
    <input type="TEXT" name="search"/><br>
    <input type="SUBMIT" name="submit" value="search"/>
</form>
  • Add **ini_set('display_errors',1);** on the line after ** – user2182349 May 31 '16 at 02:05
  • @user2182349 believe it or not and strangely enough, that (error reporting) won't throw them anything. Forms fail silently when using POST arrays and no (post) form method. – Funk Forty Niner May 31 '16 at 02:08
  • 1
    If you are searching you might want to use `like` or full text searching rather than `=`. The `=` will require an exact match.. – chris85 May 31 '16 at 02:11
  • 1
    Please also remember to accept answers when they resolve your issue. It looks like you may have missed a few, http://stackoverflow.com/a/34314174/4333555. For more reading about accepting, http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work. – chris85 May 31 '16 at 02:12
  • 1
    @Fred-ii- - excellent point. Leaving my comment so others can learn from yours. – user2182349 May 31 '16 at 02:13
  • @user2182349 *Cheers* - Yeah, I learned that one the hard way "once" *lol* – Funk Forty Niner May 31 '16 at 02:14

1 Answers1

2

Your form doesn't specify method which defaults to GET and you're using $_POST arrays.

Therefore, you need to specify a "post" method for it.

Also, look into using PDO instead of raw mysqli connections for some very important benefits.

Community
  • 1
  • 1
Cryptic
  • 406
  • 1
  • 4
  • 13