1

I realize most SQL statement in my application can be junk or hack with the plus sign (+)

Onece I type + inside the Input it fetches result from database but this is not what I want. Earlier this morning I have done research to solve this but to no avail.

I thought using the mysqli_real_escape_string() will secure this but it does me no good.

please can someone help because once there is no column with that character I don't expect result from the database.

below is some of my SQL statement.

Thank you.

//Get the recipient a user wants to send message
if(isset($_POST['recipname']) && !empty($_POST['recipname'])){
       $recipname   =   mysqli_real_escape_string($dbc_conn,trim($_POST['recipname']));
       $recipname   =   preg_replace('/\s+/', ' ',$recipname);

       $sql    =   "
        SELECT      id, username,firstname ,
                    lastname , avatar ,
                    school

        FROM        $table_name 
        WHERE       CONCAT('%', firstname,' ',lastname,'%') LIKE '%$recipname%' OR 
                    CONCAT('%', lastname,' ',firstname,'%') LIKE '%$recipname%'
        LIMIT       6 
        ";



//Query database

       }
james Oduro
  • 673
  • 1
  • 6
  • 22

0 Answers0