I have the following code to convert my UITextView text into an encoded NSString that I can insert into my database along with other stuff. The insert works perfectly fine except when there is a single quotation mark... then it doesn't work. When I NSLog the encoded NSString, the ' was not even converted into anything. So when it goes to do the web server request the url has the ' still in it which is causing it to fail... Why is the single quotation marks not getting encoded priorly? Here is my code (also I am not very good with php):
iOS:
NSString *encodedString = (NSString
*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
NULL, (CFStringRef)self.textView.text, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 ));
NSString *strURL = [NSString stringWithFormat:@"http://example.org/postText.php?thePost=%@&byUserID=%@&nickname=%@", encodedString, [UniqueUserIdentification getUserID], nickname];
php:
<?php
$con=mysqli_connect("editout","editout","editout","editout");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$thePost = $_GET["thePost"];
$byUserID = $_GET["byUserID"];
$nickname = $_GET["nickname"];
mysqli_query($con,"INSERT INTO MyTable
VALUES ('$thePost', '$byUserID', '$nickname', 0, 0)");
mysqli_close($con);
?>