CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2009
    Posts
    160

    insert # sign to mysql and also pass it through ajax url

    How can i insert # sign into the database? Do i have to use a different collation?

    Also cannot pass both & and # signs through the ajax url to the php file, any work around that excepting for replacing it with delimiters?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: insert # sign to mysql and also pass it through ajax url

    Remember that & and # are URL string delimiters. You have to URL encode/decode them.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2009
    Posts
    160

    Re: insert # sign to mysql and also pass it through ajax url

    Quote Originally Posted by PeejAvery View Post
    Remember that & and # are URL string delimiters. You have to URL encode/decode them.
    How would i do that?

    I mean lets say in my query i have a certain text field which contains #

    Code:
    $qry = "insert into xyz values(null, '#1 Fan Image')";
    Do you mean i should urlencode('#1 Fan Image'); ??

    and while retrieving it decode it?

    would it have an adverse effect if the string did not contain any special characters, i mean i donot want to search for a special character and encode it only on its existance.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: insert # sign to mysql and also pass it through ajax url

    Use JavaScript's encodeURI() to pass it through the AJAX call. Then, use PHP's urldecode() on just the variable for the query string.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    May 2009
    Posts
    160

    Re: insert # sign to mysql and also pass it through ajax url

    Quote Originally Posted by PeejAvery View Post
    Use JavaScript's encodeURI() to pass it through the AJAX call. Then, use PHP's urldecode() on just the variable for the query string.
    encodeURI seems to work only for urls. But my issue is if i am passing some to be inserted into the db on an ajax call i would want the user to put in special characters like # and & as well. using encodeURI is not good for this.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: insert # sign to mysql and also pass it through ajax url

    Quote Originally Posted by [email protected] View Post
    encodeURI seems to work only for urls.
    So are you only sending as POST and not GET?

    Quote Originally Posted by [email protected] View Post
    i would want the user to put in special characters like # and & as well. using encodeURI is not good for this.
    encodeURI would not affect inputing special characters into the database at all if you remembered to decode them on the server-side...as I suggested.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured