471,830 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,830 software developers and data experts.

Trouble with Ajax: can't insert words into mysql with characters like ', e.g. "don't"

hei coild somebody help me with ajax mysql ?
I use ajax to put data to my database but why i can not put the charector like ' \ ? for example i want to put the word DON'T which has the 'it could not do it why ? what should i do ?
Apr 30 '09 #1
7 1655
I can not put the charector like \ ' to the data base.
I use ajax to put the data to my database and i found today that i can not put these kinds of charector to my database at all. every word which contents ' can not be sent for example don't can't \
But when i tried to put the data to database with the normal method (none ajax) so i could do that.
Ajax is cool and quick but how could i fix this problem ? have somebody here the same prblem as me ?
Apr 30 '09 #2
8,658 Expert Mod 8TB
did you escape the values (PHP side)? (e.g. mysql_real_escape_string() or (my personal favourite) by a Prepared Statement)
May 1 '09 #3
16,027 Expert Mod 8TB
Welcome to Bytes!

If that suggestion doesn't work, post your code.

PS. posts split off from other threads. Please post a new thread for posts rather than hijacking other members' threads. Thanks.
May 1 '09 #4
How to do that ?
I tried this one but atill not work

Expand|Select|Wrap|Line Numbers
  1.     // $sql= sprintf("INSERT INTO tb_music VALUES ('$playlist_id','$playlist_name','$user_id','$song','$artist','$plass')",,
  2.                     mysql_real_escape_string($artist, $sql),
  3.                     mysql_real_escape_string($plass, $sql),
  4.                     mysql_real_escape_string($playlist_name, $sql),
  5.                     mysql_real_escape_string($playlist_id, $sql));
  7. //
May 1 '09 #5
16,027 Expert Mod 8TB
That's not correct PHP. Have you had a look at the PHP manual? You mentioned that your code worked when not using Ajax. Are you sure about that?
May 1 '09 #6
oh yeah, i got it.
it's just one line to fix it and it is:
$artist = mysql_real_escape_string($_POST['artist']);

your answer is my angel you know ? if i don't have you maybe i have tp geot headach for more time. thanks so much.
May 3 '09 #7
16,027 Expert Mod 8TB
That looks more like it. Glad to see that you fixed it.
May 3 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by David Cameron | last post: by
3 posts views Thread by Giggle Girl | last post: by
reply views Thread by thepisu | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.