Jump to content

Conditional Header redirect not working...


Jim R
Go to solution Solved by Jim R,

Recommended Posts

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



 

Link to comment
Share on other sites

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 by NotionCommotion
Link to comment
Share on other sites

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 by Jim R
Link to comment
Share on other sites

  • Solution

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.  

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.