Jump to content

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


helloworld001

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.