Jim R Posted January 13, 2018 Share Posted January 13, 2018 A form posts to a_players_reviews directly. It then pushes information to this code below to check if a corresponding Row exists in a_players. If it doesn't, I want to redirect it to page where my User can add more information in a second form. I know this works down to the if (($num_rows) == 0) { because I got some help here in rearranging the functions, and at that time it was to enter a Row into a_players itself. However, now I just want to redirect to a page with a second form on it. When I enter a name that already exists, the form works as it should. When I enter a name that doesn't exist, triggering the IF, I get an AJAX error. I think I have the Header syntax correct, but this is the first time I've tried this. $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') ); $nameFirst = $data['f_nameFirst']; $nameLast = $data['f_nameLast']; $grade = $data['f_grade']; 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); if (($num_rows) == 0) { header("Location: /ccoaches/player-input"); /* Redirect browser */ exit; } Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted January 13, 2018 Share Posted January 13, 2018 (edited) What ajax error do you get? Use chrome, etc debugger to look at your post response. Or better yet, enable php error reporting, and check what that says. Note that you will get an error if the server sends any content to the client before the header. This can even be an empty space. Check if include (ABSPATH ."resources/connection.php"); might be doing so. Note the following will result in an error: <?php include (ABSPATH ."resources/connection.php"); header("Location: /ccoaches/player-input"); /* Redirect browser */ <?php //bla bla bla ?> Why? Because there is a space after the included files closing php tag. Such is a reason why many will not use the final closing tag. Edited January 13, 2018 by NotionCommotion Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 13, 2018 Author Share Posted January 13, 2018 Here is connection.php <?php $con = mysql_connect("localhost","username","password"); mysql_select_db("table", $con); ?> Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted January 13, 2018 Share Posted January 13, 2018 Is there any chance that there is an empty line before your opening php tag or after your closing php tag? What does PHP say is the problem? Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 13, 2018 Author Share Posted January 13, 2018 There are no line before or after the php tags. Not sure about enabling error reporting. Where does that go? I have a log file set up. Should I send it to that? I'm using Safari. Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted January 13, 2018 Share Posted January 13, 2018 try replacing if (($num_rows) == 0) with if ($num_rows == 0) Quote Link to comment Share on other sites More sharing options...
Barand Posted January 13, 2018 Share Posted January 13, 2018 Not sure about enabling error reporting. Where does that go? In your php.ini file. Set the error reporting level to E_ALL. The usual convention is to display errors when developing and log errors on the production server. Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 13, 2018 Author Share Posted January 13, 2018 try replacing if (($num_rows) == 0) with if ($num_rows == 0) The IF loop isn't part of the problem. It's already proven to work, and even in this instance it's working. Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 13, 2018 Author Share Posted January 13, 2018 (edited) In your php.ini file. Set the error reporting level to E_ALL. The usual convention is to display errors when developing and log errors on the production server. It already is. I doubt I'm doing much in a conventional manner. Edited January 13, 2018 by Jim R Quote Link to comment Share on other sites More sharing options...
Solution Jim R Posted January 15, 2018 Author Solution Share Posted January 15, 2018 I figured out there was an Ajax setting blocking the redirect with the form plugin I'm using. No clue why it would do that, but by turning it off it took care of my problem. As always, guys, thank you for your time and help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.