Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

What I am trying to do is save the arabic text in My SQL.

My SQL Table has collation as utf8_general_ci

I have textfield in iPhone app and I am saving data using PHP.

PHP Code looks like below.

$con = mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die("Unable to select database");


$propType = $_POST['propType'];
$price = $_POST['price'];
$type = $_POST['type'];
$zone = $_POST['zone'];
$location = $_POST['location'];
$no_floor = $_POST['no_floor'];
$no_apt = $_POST['no_apt'];
$basement = $_POST['basement'];
$area = $_POST['area'];
$addedBy = $_POST['addedBy'];
$imagePath = $_POST['imagePath'];
$saleType = $_POST['dummy001'];
$mauka = $_POST['mauka'];
$mobileNumForDial = "0";


$result = mysql_query("SELECT mobileNumber FROM userInfo WHERE username='$addedBy'");
while($data = mysql_fetch_row($result)){
    $mobileNumForDial=$data[0];
}

$sql = mysql_query("INSERT INTO buildingData (propType, price, type, zone, location, no_floor,
        no_apt, basement, area, addedBy, imagePath, dummy001, dummy002, mauka) 
        VALUES 
        ('$propType', '$price', '$type', '$zone', '$location', '$no_floor', '$no_apt', '$basement', 
        '$area','$mobileNumForDial','$imagePath', '$saleType', '', '$mauka')");

iPhone code looks like below

if ([btnImage.accessibilityIdentifier isEqualToString:@"no_image"]) {
    imageSet = @"missing";
} else {
    imageSet = @"set";
}
post = [[NSString alloc] initWithFormat:@"propType=%d&price=%@&type=%d&zone=%d&location=%d&no_floor=%d&no_apt=%d&basement=%d&area=%@&addedBy=%@&imagePath=%@&dummy001=%d&mauka=%@",
        realEstatePV.selectedItem,
        priceData.text,
        typePV.selectedItem,
        areaPV.selectedItem,
        regionPV.selectedItem,
        floorData.text.intValue,
        aptData.text.intValue,
        basementPV.selectedItem,
        areaData.text,
        [keychainItem objectForKey:kSecAttrAccount],
        imageSet, salePV.selectedItem, mauka.text];
postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

postLength = [NSString stringWithFormat:@"%d", [postData length]];

url = [NSURL URLWithString:@"http://www.smart-kw.com/sama/saveBldgData.php"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];


NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if( theConnection )
{
    indicator.hidden = NO;
    [indicator startAnimating];
    webData = [[NSMutableData data] retain];
}
else
{
    NSLog(@"Internet problem maybe...");
}

The problem is

When I am storing english data, it is fine.

However when I type arabic text, it gets stored as ??? in mysql database.

Any idea why this is happening?


Edit 1

I also tried with below but still data is getting stored as *???

mysql_query("SET NAMES 'utf8'"); 
mysql_query('SET CHARACTER SET utf8');

$sql = mysql_query("INSERT INTO buildingData (propType, price, type, zone, location, no_floor,
        no_apt, basement, area, addedBy, imagePath, dummy001, dummy002, mauka) 
        VALUES 
        ('$propType', '$price', '$type', '$zone', '$location', '$no_floor', '$no_apt', '$basement', 
        '$area','$mobileNumForDial','$imagePath', '$saleType', '', '$mauka')");
share|improve this question
 
Hope this post helps stackoverflow.com/questions/11706846/… –  AlvinArulselvan Jun 12 at 9:21
 
this might help you stackoverflow.com/questions/17013298/… –  echo_Me Jun 12 at 9:23
 
you must make your editor program in utf-8 also –  echo_Me Jun 12 at 9:23
 
possible duplicate of UTF-8 all the way through –  RandomSeed Jun 12 at 9:31
add comment

2 Answers

up vote 0 down vote accepted

Try to set the postData to be encoded with UTF 8 instead of ASCII encoding:

postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
share|improve this answer
 
exactly.. I did this yesterday and it worked... still thanks for all help... –  Fahim Parkar Jun 13 at 7:48
add comment

Try To:

[theRequest setValue:@"charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.