0

I have the following code for a page where i am using a header function :

        <?php
        if (!defined('pagescope')) die('Please Try your Luck Somewhere else! Your IP Address has been logged!');
        define('pagescope', 'true');
        require'config.php';

                            *some Query processing with no echo command                                      

                            //$query1 = "select * from users";
                            if($query_run = mysql_query($query))
                            {                                                                    

                                $id=mysql_insert_id();

                                header("Location:     http://www.pingcampus.com/mysql/cropupload/jquery_upload_cropv1.2/upload_dp.php?id=$id&email=$contact_email&gender=$gender");
                                } else {
                                    echo mysql_error();

                                }                                               

                               ?>

*I Have made sure that there are no echo statements on the page, also there are no errors given! But it just doesn't redirects! Also it works fine on my Localhost but not on my hosting *

6
  • get rid of ?> if it's at the last line, do the same for config.php and see if the problem's gone Commented Jun 4, 2012 at 3:56
  • Perhaps you should turn on error reporting, then (for development)? Or check the error logs? Commented Jun 4, 2012 at 3:57
  • @Robbie i haven't mentioned error_reporting(0); anywhere in the code that itself means that it should give me errors if there are any right? Commented Jun 4, 2012 at 3:59
  • @AnilJain not necessarrily chances might be ou have error eporting turned of in your PHP.ini, try placing the code error_reporting(E_ALL) on top of your page and see if you get any error Commented Jun 4, 2012 at 4:01
  • Quite the opposite. On a production server the error_reporting level is usually low (you want to increase it for debugging) and display_errors is et to "off". You can turn display errors to "on" for debugging, then turn off when exposed to the world. Or, as I said, check the logs. Commented Jun 4, 2012 at 4:02

2 Answers 2

1

try this

$result = mysql_query($query) or die(mysql_error());
if($result) {
    $id = mysql_insert_id();
    header("Location:http://www.pingcampus.com/mysql/cropupload/jquery_upload_cropv1.2/upload_dp.php?id=$id&email=$contact_email&gender=$gender");
}

UPDATE :

your error states that header is already being sent, do a proper check in other part of script. or what you can do is use output buffering.

place ob_start(); on top of your script.

this will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

more information here. http://php.net/ob_start

Sign up to request clarification or add additional context in comments.

6 Comments

can you tell me what exact lines of code should i replace for this one?
Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web054/b548/ipg.pingcampuscom/mysql/register.php:6) in /hermes/bosweb/web054/b548/ipg.pingcampuscom/mysql/form.php on line 74 this is the error i am getting after error_reporting(E_ALL); I understand this is due to some output somewhere in the files, but i think i have to put some outputs there, is there any way around?? Any other function rather than header();
that means the header is already being sent in some part of script, if you want to get it to work then place ob_start(); at top of your code. just after error_reporting()
umm , okay thanks for the help but, I have a page called register.php which includes 12388.php which includes user_register.php which again includes form.php Ignore why have i done that What i want to ask is on which page should i place ob_start();
if any of the page have any HTML element being printed or echo function used then that may be the cause of problem.
|
0

Use ob_start() for output buffering. Check the manual Link- Manual Link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.