Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apostrophe during Insert (Mysql)

Tags:

php

mysql

insert

I am getting data though a PHP text box and inserting it into a MySQL database with a normal insert command. The text box takes in a comment frm the user for a particular Accession ID next to the text box. The problem is that when a user types in apostrophe (') for example the sentence "We have to take care of the PC's", an error is thrown.

I know why its happening because the SQL assumes it as the end of the string for that value but I don't know how to escape it. I would prefer escaping it in MYSQL.

If I escape it in MySQL can it still be exploited as SQL injection even if no error is generated and the insert works fine?

like image 472
Ank Avatar asked Aug 25 '26 06:08

Ank


2 Answers

Use mysql_real_escape_string(), or better yet, use parameterised queries with PDO.

like image 156
alex Avatar answered Aug 27 '26 20:08

alex


use the function mysql_real_escape_string()


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!