Home › Forums › Quform WordPress › quform_post_process_X hook…
- This topic has 4 replies, 2 voices, and was last updated 6 years, 3 months ago by jwrbloom.
- AuthorPosts
- January 8, 2018 at 2:24 pm #23739jwrbloomParticipant
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);
January 8, 2018 at 2:30 pm #23740jwrbloomParticipantSo 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.
January 8, 2018 at 5:08 pm #23746jwrbloomParticipantUPDATE 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);
January 10, 2018 at 2:27 pm #23795AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 10, 2018 at 2:49 pm #23796jwrbloomParticipantIt 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.
- AuthorPosts
- You must be logged in to reply to this topic.