jimmyt1988 Posted November 14, 2010 Share Posted November 14, 2010 Hi all, Is there a way to get jquery ajax to run a specific PHP function. At the moment Im sending extra paramaters like check=1: ajaxCall: function(process, obj, type){ $.post("registration-post.php", type + "=" + process + "&check=1", function(data){ alert(data); if(data==""){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ //registration.validationCollection.push($.trim(data)); $('.error').append($.trim(data) + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; } } ); } then doing an if statement, if($_POST["check"]==1){ $registration->checkDuplication(); } if($registration->validationBool){ $registration->validateFields(); } but its not really doing the job i need it to do. I'm a little stuck in my own battle to make cleaner coding Link to comment https://forums.phpfreaks.com/topic/218668-make-ajax-run-a-specific-php-function/ Share on other sites More sharing options...
BlueSkyIS Posted November 14, 2010 Share Posted November 14, 2010 can you expand a little on "its not really doing the job i need it to do"? What are you trying to do? Link to comment https://forums.phpfreaks.com/topic/218668-make-ajax-run-a-specific-php-function/#findComment-1134184 Share on other sites More sharing options...
jimmyt1988 Posted November 22, 2010 Author Share Posted November 22, 2010 function checkDuplication(){ $this->connection = new connection(); $this->connection->connect(); //$this->loadData(); if(count($_POST) > 0){ $keys = array_keys($_POST); foreach($keys As $field){ $postData = $_POST[$field]; $postField = $field; } } //line 97 $matchUser = mysql_num_rows(mysql_query("SELECT " . $postField . " FROM " . $this->table . " WHERE '" . $postField . "' = '" . $postData . "'")); if($matchUser>=1){ exit("The " . $postField . " you have entered is already registered. Please try another!"); }else{ $this->validationBool = true; exit(); } } I call this duplication function twice... once to check if the email is duplicate, and once to check if username is duplicate.. these function triggers are sent from ajax posts. Why would I be getting the error: Warning: mysql_num_rows() expects exactly 1 parameter, 2 given in D:\InstallationFiles\wamp\www\*****.co.uk\www\*****.php on line 97 Link to comment https://forums.phpfreaks.com/topic/218668-make-ajax-run-a-specific-php-function/#findComment-1138037 Share on other sites More sharing options...
jimmyt1988 Posted November 22, 2010 Author Share Posted November 22, 2010 Ah I see... Because I added *check=1 to the ajax, my little for loop is putting 2 post datas into the mysql. Anyway of removing a Post entry from the Post array Link to comment https://forums.phpfreaks.com/topic/218668-make-ajax-run-a-specific-php-function/#findComment-1138056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.