Domanda

I have an app in PHP , I am getting first Name and last Name from several sources, (API's ,files etc) Suppose I get Name like john', john", How I can save the name as it is in the Database, the '," could be at any place,The problem is that when I write query like

Insert into table values('".$a."');

so If $a contains name John' then the query becomes Insert into table values('John''); which is wrong,( 2 ' at the end) How to cater these scenario in PHP?

È stato utile?

Soluzione

$string=mysqli_real_escape_string($connection,$string);

This function is used to create a legal SQL string that you can use in an SQL statement. The given string is encoded to an escaped SQL string, taking into account the current character set of the connection.

Reference

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top