helloworld001 Posted January 8, 2015 Share Posted January 8, 2015 So I have a simple query that adds a text record into a MySQL database table. It works great with exception of one thing. I noticed that if I have "&" symbol in my paragraph, the text after that symbol won't be inserted into the table. The text before that symbol will insert fine. It seems to be doing that only with & symbol; other symbols insert and show up fine. can anyone tell me why this is happening? Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/ Share on other sites More sharing options...
ginerjm Posted January 8, 2015 Share Posted January 8, 2015 Are you using a GET to submit your data? Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502089 Share on other sites More sharing options...
helloworld001 Posted January 8, 2015 Author Share Posted January 8, 2015 Are you using a GET to submit your data? Nope. POST. Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502091 Share on other sites More sharing options...
helloworld001 Posted January 8, 2015 Author Share Posted January 8, 2015 I just noticed something else. & symbol works fine in my regular form. It's only when I am processing the form with ajax that it gives me that issue. Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502092 Share on other sites More sharing options...
ginerjm Posted January 8, 2015 Share Posted January 8, 2015 I believe this article explains why it happens. Don't know how to remedy it tho. I'm sure someone (Jacques1?) will be along shortly. https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502093 Share on other sites More sharing options...
CroNiX Posted January 8, 2015 Share Posted January 8, 2015 What are you using to post the form via ajax? Post that relevant JS code. Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502100 Share on other sites More sharing options...
helloworld001 Posted January 8, 2015 Author Share Posted January 8, 2015 Here is the js code. <script> $(document).ready(function(){ function showComment(){ $.ajax({ type:"post", url:"process.php", data:"action=showcomment", success:function(data){ $(".large-sub-records").html(data); } }); } showComment(); $("#submit").click(function(){ var name=$("#name").val(); var message=$("#details").val(); $.ajax({ type:"post", url:"process.php", data:"name="+name+"&details="+message+"&action=addcomment", success:function(data){ showComment(); } }); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502106 Share on other sites More sharing options...
ginerjm Posted January 8, 2015 Share Posted January 8, 2015 You say you're using post yet you are constructing the url like a get - and a get is going to have that extra & in it, thus messing the whole thing up. Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502108 Share on other sites More sharing options...
helloworld001 Posted January 8, 2015 Author Share Posted January 8, 2015 You say you're using post yet you are constructing the url like a get - and a get is going to have that extra & in it, thus messing the whole thing up. JS isn't my speciality. Can you tell me how I can fix it? Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502109 Share on other sites More sharing options...
mac_gyver Posted January 8, 2015 Share Posted January 8, 2015 ginerjm, the url query string data format is one of the possible ways of supplying the data parameter in the .ajax() method. if you instead supply an object as the data parameter, of the form {key1: 'value1', key2: 'value2'}, it will be urlencoded by jquery when it converts the object internally to the query string format. Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502110 Share on other sites More sharing options...
helloworld001 Posted January 8, 2015 Author Share Posted January 8, 2015 ginerjm, the url query string data format is one of the possible ways of supplying the data parameter in the .ajax() method. if you instead supply an object as the data parameter, of the form {key1: 'value1', key2: 'value2'}, it will be urlencoded by jquery when it converts the object internally to the query string format. Can you show me how you would input your method in my code? data:"name="+name+"&details="+message+"&action=addcomment", I tried it and no success. Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502112 Share on other sites More sharing options...
Solution kicken Posted January 8, 2015 Solution Share Posted January 8, 2015 data: {name: name, details: message, action: 'addcomment'} Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502119 Share on other sites More sharing options...
helloworld001 Posted January 8, 2015 Author Share Posted January 8, 2015 data: {name: name, details: message, action: 'addcomment'} I think you need to switch the "message" and "details" in your data. Here is the new code. It doesn't work. It doesn't process the form. $("#submit").click(function(){ var name = $("#name").val(); var message = $("#details").val(); $.ajax({ type:"post", url:"process.php", data: {name: name, message: details, action: 'addcomment'} success:function(data){ showComment(); } }); }); Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502122 Share on other sites More sharing options...
requinix Posted January 8, 2015 Share Posted January 8, 2015 Did you happen to try with details/message in the order kicken said to use? Because he was right. Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502123 Share on other sites More sharing options...
helloworld001 Posted January 8, 2015 Author Share Posted January 8, 2015 Did you happen to try with details/message in the order kicken said to use? Because he was right. SILLY SILLY SILLY ME! Yes his method is correct. I forgot to put "," at the end. That's all. Works like a charm! Quote Link to comment https://forums.phpfreaks.com/topic/293740-well-this-is-strange-and-new-issue-with-symbol-and-mysql/#findComment-1502124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.