Login error in php

error - Fatal error: Call to a member function real_escape_string() on a non-object in C:\xampp\htdocs\elearning\teacher_modal.php on line .

Can anyone help me with the correct code

        <?php
        if (isset($_POST['login_teacher'])) {

            function clean($str) {
                $str = @trim($str);
                if (get_magic_quotes_gpc()) {
                    $str = stripslashes($str);
                }
                return mysql_real_escape_string($str);
            }

            $username = clean($_POST['username']);
            $password = clean($_POST['password']);

            $query = mysql_query("select * from teacher where username='$username' and password='$password'") or die(mysql_error());
            $count = mysql_num_rows($query);
            $row = mysql_fetch_array($query);


            if ($count > 0) {
                session_start();
                session_regenerate_id();
                $_SESSION['id'] = $row['teacher_id'];
                header('location:teacher_home.php');
                session_write_close();
                exit();
            } else {
                session_write_close();
                ?>
                <div class="pull-right">   
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                    <div class="alert alert-danger"><i class="icon-remove-sign"></i>&nbsp;Access Denied</div>
                </div>
                <?php
                exit();
            }
        }
        ?>

5 posts were merged into an existing topic: Need Help with my php mysql code