Your request will appear (EDIT: appeared, in the first version of the request), completely static - that is, it does not use the data provided by the user. In this case, there is no risk of SQL injection.
SQL injection attacks include entering user data and including it directly in a SQL query instead of the preferred method of using a parameterized SQL statement, including the values ββprovided by the user. (I donβt know the details of how this is done in PHP ... I certainly hope this is possible.)
EDIT: Ok, now you have changed your code, including:
$a1="SELECT hosteladmissionno,student_name,semester FROM registration WHERE mess_type ".$q."' AND status_flag=1";
Where $q is retrieved from the text box. Now I assume that you really meant the second line:
WHERE mess_type='".$q."' AND status_flag=1";
But it is still vulnerable to SQL injection attack. Suppose q is:
' OR 'x'='x
As a result, your SQL statement will end as
SELECT hosteladmissionno,student_name,semester FROM registration WHERE mess_type='' OR 'x'='x' AND status_flag=1
which is clearly not the logic you are following.
You must use the parameters for the values ββas shown on this page in the prepared PHP page .
source share