quform_post_process_X hook…

Home Forums Quform WordPress quform_post_process_X hook…

This topic is: not resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #23739
    jwrbloom
    Participant

    I’m taking the data from a form and posting it directly to a_players_reviews (APR). However, I also want to check a_players (AP) to see if there is a Row corresponding to the name (basketball players) being added to APR. If there isn’t, I want to add a row to AP.

    So I’ve created a plugin for quform_post_process_X.

    I need to check the player’s first name, last name and grade because we do have examples of similar name.

    The form is definitely passing variables, but clearly I’m missing something.

    
     add_action('quform_post_process_1', function (array $result, Quform_Form $form){
        $data = array(
            'f_school' => $form->getValue('quform_1_7'),
            'f_grade' => $form->getValue('quform_1_5'),
            'f_nameFirst' => $form->getValue('quform_1_3'),
            'f_nameLast' => $form->getValue('quform_1_4')
        );
     
     			Quform::log($data['f_school']);
     			Quform::log($data['f_grade']);
     			Quform::log($data['f_nameFirst']);
     			Quform::log($data['f_nameLast']);
    
     
    			$query = "SELECT nameFirst,nameLast,grade 
    						FROM a_players
    						WHERE nameFirst = '" . $data['f_nameFirst'] ."' and nameLast = '" . $data['f_nameLast'] . "' and grade = '" . $data['f_grade'] ."'";
    			
    			$results = mysql_query($query);
    			
      
    					if (mysql_num_rows($results) == 0) {
    			 			"INSERT INTO a_players (school, grade, nameFirst, nameLast)
    						VALUES ('".$data['f_school']."', '".$data['f_grade']. "', '" .$data['f_nameFirst']. "', '" .$data['f_nameLast']."')";
    					}			
    
    		return $result;	
     
    }, 10, 2);
    
    
    #23740
    jwrbloom
    Participant

    So I added…

    Quform::log(mysql_error());

    …to my code.

    And it came up with this.
    [08-Jan-2018 14:26:50 UTC] string(62) “Access denied for user ‘root’@’localhost’ (using password: NO)”

    Should I added my connection call to this file? I thought it would already be connected to AP since it’s posting to APR table.

    #23746
    jwrbloom
    Participant

    UPDATE code: added this line:

    $num_rows = mysql_num_rows($results);

    …then put the $num_rows in the IF loop.

    I’ve tested with information I know exists in a_players, but it’s still showing $num_rows as NULL.

    
    add_action('quform_post_process_1', function (array $result, Quform_Form $form){
        $data = array(
            'f_school' => $form->getValue('quform_1_7'),
            'f_grade' => $form->getValue('quform_1_5'),
            'f_nameFirst' => $form->getValue('quform_1_3'),
            'f_nameLast' => $form->getValue('quform_1_4')
        );
     
     			Quform::log($data['f_school']);
     			Quform::log($data['f_grade']);
     			Quform::log($data['f_nameFirst']);
     			Quform::log($data['f_nameLast']);
    
    include (ABSPATH ."resources/connection.php");
    
     
    			$query = "SELECT nameFirst,nameLast,grade 
    						FROM a_players
    						WHERE nameFirst = '" . $data['f_nameFirst'] ."' and nameLast = '" . $data['f_nameLast'] . "' and grade = '" . $data['f_grade'] ."'";
    			
    			$results = mysql_query($query);
    			$num_rows = mysql_num_rows($results);
    			
    			Quform::log(mysql_error());
    			Quform::log(mysql_num_rows());
    			
    			Quform::log($results['nameFirst']);
    		
    		//	while($check = mysql_fetch_assoc($results)) {			
      
    					if (($num_rows) == 0) {
    			 			"INSERT INTO a_players (school, grade, nameFirst, nameLast)
    						VALUES ('".$data['f_school']."', '".$data['f_grade']. "', '" .$data['f_nameFirst']. "', '" .$data['f_nameLast']."')";
    					}			
    
    		return $result;	
     
    }, 10, 2);
    
    
    #23795
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #23796
    jwrbloom
    Participant

    It had it return all data, limit 10. It didn’t return anything.

    Once I get through this process, I’m going to look into converting my queries to mysqli. Not sure about this PDO stuff. I’ll email you the information you asked.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy