Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    DKY
    DKY is offline
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php/jquery validate and then update(mysql)

    I'm really struggling here trying to get some validation in place for my ajax. I am using jQuery with php right now to update a mysql table. I'm currently trying to figure out how to put a warning in a popup alert that says that I can't have a frompdc value the same as a topdc value. Today I have jQuery that says:

    Code:
    $("#frompdc<?php echo $JavaCnt;?>").change(function(){
    	var id     = $('#id<?php echo $JavaCnt;?>').attr('value');
    	var frompdc     = $('#frompdc<?php echo $JavaCnt;?>').attr('value');
    	var topdc     = $('#topdc<?php echo $JavaCnt;?>').attr('value');
    	//alert("firm=frompdc&id="+ id + "&frompdc=" + frompdc + "&topdc=" + topdc) 	
    		$.ajax({
    			type: "POST",
    			url: "AJ_Update.php",
    			data: "firm=frompdc&id="+ id + "&frompdc=" + frompdc + "&topdc=" + topdc
    		});		
    	return false;
    	}
    	);
    Which seems to work out beautifully with this php on another page:

    Code:
    IF($_POST['frompdc'] <> $_POST['topdc'])
    		{
    			mysql_query("UPDATE TBLTRANSFERS SET FROMPDC = ".$_POST['frompdc'].", MOD_TS = '". $timenow ."' WHERE ID = ".$_POST['id']); 
    		}
    I changed my php to say
    Code:
    		IF($_POST['frompdc'] <> $_POST['topdc'])
    		{
    			mysql_query("UPDATE TBLTRANSFERS SET FROMPDC = ".$_POST['frompdc'].", MOD_TS = '". $timenow ."' WHERE ID = ".$_POST['id']); 
    		}ELSE{
    			ECHO "Can't be the same";
    		}
    but can't figure out how to get that echo to go back to my jQuery and display an alert box with that text. Help?
    Last edited by DKY; 03-02-2011 at 09:14 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •