0

I am inserting value which contains & character, but the value breaks after & while it's inserted in database. Can anyone please help me to insert value with & character?

My filed's datatype is varchar(50) and collation is utf8_general_ci.

I have used code:

    NSString  *strUr=[NSString stringWithFormat:@"%s%s?event_name=%@&id=%@",ServerPath,URLAddEvent,eventName,ID];


    strUr = [strUr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"url : %@",strUr);

    request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:strUr]];

    con=[[NSURLConnection alloc]initWithRequest:request delegate:self];

    if(con)
    {
        webdata=[NSMutableData data];
    }

in my ios code.

Any needful help will be appreciated.

Shah Paneri
  • 729
  • 7
  • 28

1 Answers1

0

You can escape any special characters. you need to identify them using string manipulation and then create the sql accordingly.

See My fiddle.

Inserting into table:

INSERT INTO Table1
    (`id`, `col1`)
VALUES
    (1, 'test\&'),
    (2, 'special character \''),
    (3, 'speacial character \"'),
    (4, 'test'),
    (5, 'testing'),
    (6, 'test')
;

Selection from table:

select * from Table1 where col1 like '%&%' or col1 like '%\'%'
Aditya
  • 2,876
  • 4
  • 34
  • 30