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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.