Statik Stasis
Statik Stasis

Reputation: 308

PHP Redirect Not Working on Script Containing SQL Queries

Alright so I've been pouring over this code for 16+ hours and I cannot find where the issue is. Before you say anything- I know I'm prone to SQL injection and I need to setup more prepared statements; once I get the code working my next step is to work on those issues. I also know I need to add the TRUE and 303 parameter to the Header call- I'm just trying to get it running at this point.

The code worked beautifully until I began working on eliminating form submission on refresh and adding redirects at the end.

The page that is having the problem is called updateorder.php and here is a Pastie link for it: http://pastie.org/9188291

I created a page called Issue.php to funnel everyone off the page and to eliminate the possibility of any of the html code outputting. That did not help. I removed the ?> PHP closing tag from the end since all the code is PHP and eliminate any white space possibility. That didn't help either.

The page before this has several submit buttons. This page looks at what button was pushed and runs the code when it meets the conditions of the IF.

Here are the problems:

If I hit the UpdateOnly button and $ThisStatus does ==1, then it remains on this page (updateorder.php) and the screen is blank. The exact thing happens if I use the UpdateCommit button.

Something is happening when it runs this particular section of the UpdateOnly script: Sorry I don't have 10 reputation so it will not let me provide more links. Here is the Pastie number you can replace in the above Pastie link to see the code for this section: 9188298

And something happens when running this particular section of the UpdateCommit script: Sorry I don't have 10 reputation so it will not let me provide more links. Here is the Pastie number you can replace in the above Pastie link to see the code for this section: 9188306

Whatever it is doing it is causing it not to redirect. The SQL code executes and does everything it is supposed to do in the database; it's updating the order, it's updating inventory- all of that executes fine- it's just not redirecting and it stalls somewhere in the script before it redirects and leaves me with a blank screen.

I've done the advanced search on the site and looked at every thing I could find using the keywords PHP, MySQL, Redirect, with no clue as to why it's not working. I've went over this code line by line to look for white space, tried using the whole website address for the redirect, added a space between the colon and the link in the header... I've tried a lot of things. I've even tried unhealthy things like banging my head on my desk, hitting my head with my palm, and pulling my hair... no results. I really appreciate your time.

Just in case- here is the code in my required db connection file: Sorry I don't have 10 reputation so it will not let me provide more links. Here is the Pastie number you can replace in the above Pastie link to see the code for this section: 9188351

By the way... as you can probably tell I'm still learning so it may not be 'beautiful code' yet but I'm working on getting there. Thanks again for your help.

Upvotes: 2

Views: 241

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

When in development add error reporting to the top of your file(s)

error_reporting(E_ALL);
ini_set('display_errors', 1);

This will signal any errors if they are found in your code.

As per the error message from your comments:

To get rid of that Cannot modify header information - headers already sent... message, place

<?php session_start(); ?><?php // rest of your code... as your first lines of code while getting rid of the other one where it's at now, followed by the rest of your code. Make sure there is nothing above that, HTML etc. including any white spaces. If you still get that error message, make sure it's saved as UTF-8 without BOM. (Consult footnotes)

For the Notice: Undefined index: UpdateOnly error message, make sure your form element is named with no typos. I.e. name="UpdateOnly" --- UpdateOnly is not the same as updateonly PHP is case-sensitive.

As for your $result->free(); you mention you don't have that function, so just remove it.


Footnotes:

  • BOM (aka byte order mark)

For more information on this subject, visit: https://en.wikipedia.org/wiki/Byte_order_mark

For more information on error reporting, visit: http://php.net/manual/en/function.error-reporting.php

Upvotes: 2

Related Questions