Jump to content

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


helloworld001
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?

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

				  });
				
			});
Link to comment
Share on other sites

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.