插入完成后,我遇到了有关重定向的问题。我在我的本地机器上测试它并且它工作正常但在godaddy网站上,插入工作正常然后停止(它不会重定向到所需页面)并返回“500内部服务器错误”。
页面执行插入和重定向
<?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';
?>
答案 0 :(得分:0)
请通过退出检查;在标题功能之后。 问题可能出在页面下方的一些相关代码中。
重定向的一种替代方法如下所示。
echo "window.location.href='your_url_goes_here'";exit;
答案 1 :(得分:0)
我在这里测试了你的文件,发现问题不在header()函数中,而是在你的文件members.php中。为了你检查它做了以下测试:
- 删除文件的所有行&#39; members.php&#39;并只输入一个简单的消息:<?php echo "<h1> test </h1>"; ?>