Jump to content

make ajax run a specific php function


jimmyt1988

Recommended Posts

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


            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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.