PDA

View Full Version : php/jquery validate and then update(mysql)



DKY
03-02-2011, 04:29 PM
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:


$("#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:


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

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?