I am able to post from my iOS app to my MySQL database but when I have long sentences for example
I am trying to post this string: "Hello, how are you today?"
It won't do anything. So I improvised and replaced the spaces with _
and my string would look like this "Hello,_how_are_you_today?"
and
that worked!
But I thought it's weird that I have to do that.
So my question is, how can I post long strings with spaces without modifying it like how I did?
Here is the code that I have
iOS
NSString *strURL = [NSString stringWithFormat:@"http://www.example.com/post.php?dishname=%@&description=%@, dishname.text, description.text]";
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@", strResult);
php code
<?php
// Create connection
$servername = "localhost";
$username = "admin";
$password = "root";
$dbname = "dbname";
$con=mysqli_connect("localhost","admin","root","dbname");
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
echo "Nothing happened";
}else{
}
if (isset ($_GET["dishname"]))
$dishname = $_GET["dishname"];
else
$dishname = "Null";
if (isset ($_GET["description"]))
$description = $_GET["description"];
else
$description = "Null";
echo "dishname : ". $dishname;
echo "description : ". $description;
$sql = "insert into RecipeFeed (DishName, Description) values ('".$dishname."','".$description."')";
$result = mysqli_query($con, $sql);
?>