This function correctly checks if the iput string is already in use by comparing it to data picked up by PHP from the databese. My problem is that when I pass this variable via Ajax it returns 'NULL' but when I pass other variables they are sent correctly, so the ajax function is working. Maybe something in my function is to blame?
var string, code, codUp, result;
function check(){
string="<?php echo $html; ?>";
code = document.getElementById('this_code').value;
codUp = code.toUpperCase();
result=string.split(" ");
if (document.getElementById('this_code').value === "")
{
return false;
}
else if (result.indexOf(codUp) === -1)
{
return false;
}
else{alert ('Code already in use.');}
};
AJAX
ajax.open('GET','agencies/gen_ag.php?action=add&name='+name+'codeUp='+codUp+'&nocomp='+nocompt_ag,true);
PHP
if($_GET['action']=='add') {
$res_seecode = mysql_query("SELECT * FROM agencies WHERE EMP_CODE = '$_GET[code]'");
if(!mysql_num_rows($res_seecode)) {
$res_add = mysql_query("INSERT INTO agencies VALUES ('NULL','$_GET[codUp]','$_GET[name]'");
echo 'Agencie created.';
}
Var_dump(); Returns name but not codUp.