I have this line of code in my iOS app that attempts to insert data into my mysql database:
NSString *strURL = [NSString stringWithFormat:@"http://example.org/postSqueal.php?thePost=%@&byUserID=%@&nickname=%@", self.textView.text, [UniqueUserIdentification getUserID], nickname];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
Basically I am getting the user to type in a bunch of stuff into a UITextView (like a twitter tweet) for example, and when they press "post" button it is supposed to store this data in my database along with some other information like their nickname. My code works perfectly fine until I started entering spaces. Then my code would not insert to the database. I found out this is because it would mean a space in the url which is not a valid url, so by this I concluded that I need to somehow surround the text view text with quotation marks in my url. I tried putting quotation marks like the following:
NSString *strURL = [NSString stringWithFormat:@"http://example.org/postSqueal.php?thePost=\"%@\"&byUserID=%@&nickname=%@", self.textView.text, [UniqueUserIdentification getUserID], nickname];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
However it still does not work. Anyone know what might be wrong? When I manually type out the url with quotation marks around text with spaces it works, but in my code when I try to add quotation marks like that, the insert doesn't work. Also is there any other characters I might have to worry about giving me trouble when converting it into the url?
Here is my php script:
<?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);
?>