I guess my question is the opposite of most I have seen..
its not trouble with INSERTING data with apostrophes..its with pulling/displaying it.
Summary/Overview:
I use PDO to insert data/records into my MySQL database (table).. this put special characters/apostrophes..etc -in- the database (when looking at the data through MyPHPAdmin, I see the apostrophes in the cells/columns if applicable)
I later pull records from the table.. and save to an array.
code example so far:
//declare PDO DB connection
$table = 'target_table';
$conn=new PDO("mysql:host=localhost; dbname=test;","root","");
$query = "SELECT * FROM $table";
$tcstmt = $conn->prepare($query);
$tcstmt->execute();
$totalEntriesArray = array();
while($u = $tcstmt->fetch(PDO::FETCH_BOTH)){
$totalEntriesArray[] = $u;
}
I populate a dropdown box.. and when the user makes a selection, I then have some js/jQuery to handle this event detection, grab the value from the dropdown box selection and my target index in the array, and populate some fields on the page.
example:
$("#dropdown").change(function(){
$('#nameField input').val(totalEntriesArray[arrayIndex].target_name);
}
(with me so far? haha)
fairly easy/straight forward...and everything works fine, and as intended.
However, I noticed that if some of the text/data from the database that has apostrophes display in these fields, show up with the infamous 'black diamond/question mark' character..
So this isnt a situation where preventing SQL injection will fix it..or using PDO will solve it...etc. Its the opposite direction. :)
I need to somehow parse/format the data so it displays in the textfields properly.
What is the best way to achieve this?
thanks.