需要帮助我的搜索栏php

I have been following this link as a guideline for my search bar https://www.youtube.com/watch?v=Wvs6sbLN3NI&t=678s

Im a beginner in php and sql please help me with this one. i dont know what to do in sql syntax. the error is, Notice: Undefined variable: q in C:\xampp\htdocs\login-system\search.php on line 21 thanks in advance.

<?php

    $con = mysql_connect('localhost','root','');
    $db = mysql_select_db('accounts');

?>
<!DOCTYPE html>
<html>
<head>
        <title> Search Form </title>
        <link rel="stylesheet" type="text/css" href="css/stylesearch.css">

</head>
<body>

    <form action = "search.php" method ="GET" id="searchForm">
        <input type="text" name="q" id="searchBox" placeholder="Search Here" value="" /><input type="submit" id="searchBtn" value ="GO" />
    </form>

    <?php
        $query = mysql_query("SELECT * FROM provider WHERE provider LIKE '%$q%' OR broker LIKE '%$q%' OR deductible LIKE '%$q%' OR deductible_waiver LIKE '%$q%' OR accredited_banks LIKE '%$q%' OR can_not_offer_mortgaged_with LIKE '%$q%' OR casa_eligibility LIKE '%$q%' OR depreciation LIKE '%$q%' OR special_quotes LIKE '%$q%' OR unit_age_limit LIKE '%$q%' OR provider_information LIKE '%$q%' OR provider_branches LIKE '%$q%' OR mmx_exclusive LIKE '%$q%' OR disclaimer LIKE '%$q%' OR accredited_shops LIKE '%$q%' OR roadside_assistance_number LIKE '%$q%' OR roadside_assistance_coverage LIKE '%$q%' OR check_addressee LIKE '%$q%' OR accounts_details LIKE '%$q%' OR cancellation_charge LIKE '%$q%'");
        $num_rows = mysql_num_rows($query);

        while($row = mysql_fetch_array($query))
        {
            $id = $row['id'];
            $prov = $row['provider'];
            $brok = $row['broker'];
            $deduc = $row['deductible'];
            $deduc_waiver = $row['deductible_waiver'];
            $accre_banks = $row['accredited_banks'];
            $mort = $row['can_not_offer_mortgaged_with'];
            $casa_elig = $row['casa_eligibility'];
            $depre = $row['depreciation'];
            $s_quotes = $row['special_quotes'];
            $age = $row['unit_age_limit'];
            $prov_info = $row['provider_information'];
            $prov_branch = $row['provider_branches'];
            $mmx_exclusive = $row['mmx_exclusive'];
            $disclaimer = $row['disclaimer'];
            $accre_shops = $row['accredited_shops'];
            $roadside_assist_no = $row['roadside_assistance_number'];
            $roadside_assist_cov = $row['roadside_assistance_coverage'];
            $check_addressee = $row['check_addressee'];
            $acc_details = $row['accounts_details'];
            $can_charge = $row['cancellation_charge'];

            echo '<h3>' .$prov .'</h3><p>'. $brok.'<br>'. $deduc.'<br>'. $deduc_waiver.'<br>'. $accre_banks.'<br>'. $mort.'<br>'. $casa_elig.'<br>'. $depre.'<br>'. $s_quotes.'<br>'. $age.'<br>'. $prov_info.'<br>'. $prov_branch.'<br>'. $mmx_exclusive.'<br>'. $disclaimer.'<br>'. $accre_shops.'<br>'. $roadside_assist_no.'<br>'. $roadside_assist_cov.'<br>'. $acc_details.'<br>'. $check_addressee.'<br>'. $can_charge.'</p><br />';
        }
    ?>

</body>
</html>

You are not really stating what your problem is here. Just looking at your code though, you are not calling your database in your mysqli query, which should be mysqli_query($db, "SELECT...."), where $db is your mysqli_connect variable. There are a few examples in the php manual: http://php.net/manual/en/mysqli.query.php.

As mickmacusa said above too, if you add in "or die (mysqli_error($db)" on the backend, it will give you more information regarding your sql syntax.

Warning mysql_query, mysql_fetch_array,mysql_connect etc.. extensions were deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

1) Try to use mysqli_* or PDO prepared statement

2) first of all follow my sample code

3) Where from your getting variable $q . you have to assign the post value to $q variable like this $q =$_GET['q']; otherwise you will get $q undefined error

        //db connection

        global $conn;

        $servername = "localhost";  //host name

        $username = "username"; //username

        $password = "password"; //password

        $mysql_database = "dbname"; //database name

    //mysqli prepared statement 

        $conn = mysqli_connect($servername, $username, $password) or die("Connection failed: " . mysqli_connect_error());

       mysqli_select_db($conn,$mysql_database) or die("Opps some thing went wrong");

         $stmt = $conn->prepare("SELECT * FROM provider
                                WHERE provider LIKE %'".$q."'% 
                                OR broker LIKE %'".$q."'% 
                                OR deductible LIKE %'".$q."'%
                                OR deductible_waiver LIKE %'".$q."'%
                                OR accredited_banks LIKE %'".$q."'% 
                                OR can_not_offer_mortgaged_with LIKE %'".$q."'%
                                OR casa_eligibility LIKE %'".$q."'%
                                OR depreciation LIKE %'".$q."'% 
                                OR special_quotes LIKE %'".$q."'%
                                OR unit_age_limit LIKE %'".$q."'% 
                                OR provider_information LIKE %'".$q."'%
                                OR provider_branches LIKE %'".$q."'% 
                                OR mmx_exclusive LIKE %'".$q."'% 
                                OR disclaimer LIKE %'".$q."'% 
                                OR accredited_shops LIKE %'".$q."'% 
                                OR roadside_assistance_number LIKE %'".$q."'% 
                                OR roadside_assistance_coverage LIKE %'".$q."'% 
                                OR check_addressee LIKE %'".$q."'% 
                                OR accounts_details LIKE %'".$q."'% 
                                OR cancellation_charge LIKE %'".$q."'%");

                            $stmt->execute();


                            $get_result =$stmt->get_result();

                            $row_count= $get_result->num_rows;




    ?>

    <!DOCTYPE html>
    <html>
    <head>
            <title> Search Form </title>
            <link rel="stylesheet" type="text/css" href="css/stylesearch.css">

    </head>
    <body>

        <form action = "search.php" method ="GET" id="searchForm">
            <input type="text" name="q" id="searchBox" placeholder="Search Here" value="" /><input type="submit" id="searchBtn" value ="GO" />
        </form>

        <?php
            if($row_count>0)
            {
                while($row = $get_result->fetch_assoc() )
                {
                    $id = $row['id'];
                    $prov = $row['provider'];
                    $brok = $row['broker'];
                    $deduc = $row['deductible'];
                    $deduc_waiver = $row['deductible_waiver'];
                    $accre_banks = $row['accredited_banks'];
                    $mort = $row['can_not_offer_mortgaged_with'];
                    $casa_elig = $row['casa_eligibility'];
                    $depre = $row['depreciation'];
                    $s_quotes = $row['special_quotes'];
                    $age = $row['unit_age_limit'];
                    $prov_info = $row['provider_information'];
                    $prov_branch = $row['provider_branches'];
                    $mmx_exclusive = $row['mmx_exclusive'];
                    $disclaimer = $row['disclaimer'];
                    $accre_shops = $row['accredited_shops'];
                    $roadside_assist_no = $row['roadside_assistance_number'];
                    $roadside_assist_cov = $row['roadside_assistance_coverage'];
                    $check_addressee = $row['check_addressee'];
                    $acc_details = $row['accounts_details'];
                    $can_charge = $row['cancellation_charge'];

                    echo '<h3>' .$prov .'</h3><p>'. $brok.'<br>'. $deduc.'<br>'. $deduc_waiver.'<br>'. $accre_banks.'<br>'. $mort.'<br>'. $casa_elig.'<br>'. $depre.'<br>'. $s_quotes.'<br>'. $age.'<br>'. $prov_info.'<br>'. $prov_branch.'<br>'. $mmx_exclusive.'<br>'. $disclaimer.'<br>'. $accre_shops.'<br>'. $roadside_assist_no.'<br>'. $roadside_assist_cov.'<br>'. $acc_details.'<br>'. $check_addressee.'<br>'. $can_charge.'</p><br />';
                }

            }


            $stmt->close();
            $conn->close();
        ?>

    </body>
    </html>