0

Hi,

Im trying to run a MYSQL query to check if the input value exists first.

A user fills in an input field and clicks "Add Tag"

The java script on the same page checks the MYSQL table if that tag is already there and if so returns a faded in DIV to say it already exists otherwise it INSERTS the value into the table and fades in a DIV saying "Tag Added to Database"

Please see my code below, it currently runs an external php file that does it for me using just php and the mysq; query.

Except i cant seem to work out how to run it inside my page so that it fades in the DIV.

<script type="text/javascript"> 

$('#i1').hide();  // this is my div that says tag inserted!
$('#i2').hide();  // this is my div that says tag already exists

$("#keyword").click(function() { 

var txt = $.ajax({
url: 'process.php',
async: true, 
type:'POST',
data:({
tag:$('input#newtag').val(),  
}) 

}).success;	

// This is where i need to add the database connect check if value exists.
// The url: 'process.php' does work for me but it dosent return my div responses because its and external file.

}); 

</script>

Thank you in advance :-)

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by jonnypixel
0

modify/update process.php so that it returns/prints/echoes:
"OK" when tag is inserted
"!OK" when tag already exists

<script type="text/javascript"> 

$('#i1').hide();  // this is my div that says tag inserted!
$('#i2').hide();  // this is my div that says tag already exists

$("#keyword").click(function() { 

	$('#i1').hide();  // this is my div that says tag inserted!
	$('#i2').hide();  // this is my div that says tag already exists

	var txt = $.ajax({
				url: 'process.php',
				async: true, 
				type:'POST',
				data:{
						tag: $('input#newtag').val()
					} ,
				success:function(data){
						if( data=='OK' )
						{
							$('#i1').show();
						}
						else
						{
							$('#i2').show();
						}
					}
				});	

}); 

</script>

Edited by hielo: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.