0

I have an issue regarding redirect after an insert is complete. I tested it on my local machine and it worked fine but on godaddy site, the insert works fine then it stops(it doesn't redirect to required page) and returns "500 Internal Server Error".

Page performing insert and redirect

<?php    
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "\panel\config.php";
include($path);
if(isset($_POST['btn-member']))
{
$ftname = trim($_POST['FIRST_NAME']);
$ltname = trim($_POST['LAST_NAME']);
$email = trim($_POST['EMAIL_ADD']);
$passw = trim($_POST['PASSWORD']);
$vpass = trim($_POST['VERIFY']);

if(empty($ftname))
{
$error = "Enter your First name !";
$code = 1;
}
else if(empty($ltname))
{
$error = "Enter your Last name !";
$code = 2;
}
else if(empty($email))
{
$error = "Enter your personal email address!";
$code = 3;
}
else if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
{
$error = "Invalid E-mail Format !";
$code = 3;
}
else if(strlen($contact) > 10)
{
$error = "Phone Number should not contain more than 10 numbers !";
$code = 4;
}
else if(empty($passw))
{
$error = "Enter a Password !";
$code = 5;
}
else if(strlen($passw) != strlen($vpass) )
{
$error = "Your Password do not match, Try Again !";
$code = 6;
}
else
{
 // Insert
$fields = array('USER_ID','FIRST_NAME','LAST_NAME','EMAIL_ADD','PASSWORD');
$_POST['PASSWORD'] = $user->hash_password($_POST['PASSWORD']);
if($insert->insert_all('members',$insert->insertString($fields,$_POST),$fields,$_POST))
{
    header("Location: members.php?inserted");
}else
{
    header("Location: members.php?failed");
}
}
}
?>

members.php

<?php 
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "\panel\config.php";
include($path);
include_once 'Header.php';
?>

            <div class="span9">
                <div class="content">

                    <div class="module">
                        <div class="module-head">
                            <h3> MEMBERS</h3>
                        </div>
                        <div class="module-option clearfix">
                            <?php
               if(isset($_GET['inserted']))
                        {
                     ?>
                     <div class="alert alert-success">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>SUCCESS</strong> YOU HAVE SUCCESSFULLY INSERTED
                    </div>
                    <?php
                         }
               else if(isset($_GET['failed']))
                         {
                      ?>
                      <div class="alert alert-error">
                            <button type="button" class="close" data-dismiss="alert">×</button>
                            <strong>ERROR!</strong> TRY AGAIN
                      </div>
              <?php
                         }
                  ?>
</div>
</div>
</div>
</div>
<?php 
include_once 'footer.php';
?>

m5kibs
  • 3
  • 4

2 Answers2

0

Please check by putting exit; right after header function. Problem is probably in some related code further down the page.

One alternative way to redirect is as per below.

echo "window.location.href='your_url_goes_here'";exit;
Rahul Patel
  • 5,248
  • 2
  • 14
  • 26
  • Please refer link for more details. http://stackoverflow.com/questions/2354026/why-is-header-causing-an-internal-server-error – Rahul Patel Jul 22 '16 at 13:54
0

I did a test your files here and found that the problem is not in the header() function, but in your file members.php . for you to check it do the following test: -Delete all lines of your file 'members.php' and put only a simple message like: <?php echo "<h1> test </h1>"; ?>

charlan alves
  • 384
  • 3
  • 17
  • Yes. both files are same directory. – m5kibs Jul 22 '16 at 13:57
  • wow I think I found the problem: this missing "exit" before header because The script continues to execute after your header() call. if ($ Insert-> insert_all ('members', $ Insert-> insertString ($ fields, $ _ POST), $ fields, $ _ POST)) {      header ("Location: members.php inserted"); exit; } else {      header ("Location: members.php failed"); exit; } – charlan alves Jul 22 '16 at 14:45
  • Am using Native php – m5kibs Jul 25 '16 at 05:49
  • I did a test site here and found that the problem is not in the header function () but in your file mebers.php.     for you to check it do the following test: -Delete all lines of your file 'mebers.php' and put only a simple message like: echo '

    test h1>';

    – charlan alves Jul 25 '16 at 12:48
  • I tried out the test, to show the message and it displayed the message. what does it mean?? – m5kibs Jul 27 '16 at 06:02
  • this mean that some of the files (members.php or "\panel\config.php" or Header.php or footer.php it has an php error. Please to post here the content these files – charlan alves Jul 27 '16 at 11:57
  • @m5kibs kindly consider accepting my answer by clicking the check (v) – charlan alves Aug 10 '16 at 14:48