You cannot do this because the method is set to protected , you must set it to public in order to be able to access it . Otherwise, you can call it only from the same class or from children of this class.
May I also suggest starting with your uppercase name: class Gindex . You can also improve the name of the class because gindex doesn't say anything about what it does. The same goes for your method name. And your parameter names are also terrible. Name things correctly so that people (including) themselves know exactly what the variable / class or method contains when they (re) view your code.
You also use the $db variable, which is nowhere in the scope of the class .
Also, please do not use mysql_* functions for new code. They are no longer supported, and the community has begun the process. See the red box ? Instead, you should learn about prepared instructions and use PDO or MySQLi . If you canβt decide, this article will help you choose. If you want to find out, here is a good PDO tutorial .
It will also eliminate the nasty SQL Injection that you have in your code. For more information on how to fix this using PDO or mysqli, see this question .
It also looks like you are using the website as a password when pasting data into the database. If you are really going to store a database, I also suggest that you read password hashing for security.
source share