Jump to content

Well this is strange and new. issue with & symbol and MySQL


Go to solution Solved by kicken,

Recommended Posts

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?

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

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>

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.

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.

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();
						  
					  }

				  });
				
			});

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.