重定向问题PHP
我得到了一个图像库crud脚本,并决定将“编辑图像”页面设置为“编辑配置文件”页面。我的问题是我添加的内容没有重定向回个人资料页面。这是我的密码:重定向问题PHP,php,Php,我得到了一个图像库crud脚本,并决定将“编辑图像”页面设置为“编辑配置文件”页面。我的问题是我添加的内容没有重定向回个人资料页面。这是我的密码: <?php // Start session session_start(); // Include and initialize DB class require_once 'DB.class.php'; $db = new DB(); // Fetch the users data $images = $db->getRows('
<?php
// Start session
session_start();
// Include and initialize DB class
require_once 'DB.class.php';
$db = new DB();
// Fetch the users data
$images = $db->getRows('images');
// Get session data
$sessData = !empty($_SESSION['sessData'])?$_SESSION['sessData']:'';
// Get status message from session
if(!empty($sessData['status']['msg'])){
$statusMsg = $sessData['status']['msg'];
$statusMsgType = $sessData['status']['type'];
unset($_SESSION['sessData']['status']);
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>SWARZIE</title>
<meta charset="utf-8">
<!-- Bootstrap library -->
<link rel="stylesheet" href="bootstrap/bootstrap.min.css">
<!-- Stylesheet file -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<style>
.form {
width: 300px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
<h1>Image Gallery</h1>
<hr>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Swarzie</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<> <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<"></a>
</li>
<li class="nav-item">
<></a>
</li>
<li class="nav-item">
<></a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
</form>
<form class="form-inline my-2 my-lg-0">
<a href="profile.php" class="profile">Profile</a>
</form>
<form class="form-inline my-2 my-lg-0">
<a href="useaccount.php?logoutSubmit=1" class="logout">Logout</a>
</form>
</div>
</nav>
<?php //from ww w .j a va2 s .c om
if ( isset( $_POST["submitButton"] ) ) {
// (deal with the submitted fields here)
header( "Location: profile.php" );
exit;
} else {
displayForm();
}
function displayForm() {
?>
<!DOCTYPE html5>
<html>
<body>
<form action="profile.php">
<label for="img">Select image:</label>
<input type="file" id="img" name="img" accept="image/*">
<input type="submit">
</form>
<form action="profile.php" method="post">
<label for="firstName">First name</label>
<input type="text" name="firstName" id="firstName" value="" />
<label for="lastName">Last name</label>
<input type="text" name="lastName" id="lastName" value="" />
<textarea rows="2" cols="30" name="comment" form="usrform">
About</textarea>
<input type="submit" name="submitButton" id="submitButton" value= "Send Details" />
</form>
</body>
</html>
<?php
}
?>
<!-- Display status message -->
<?php if(!empty($statusMsg)){ ?>
<div class="col-xs-12">
<div class="alert alert-<?php echo $statusMsgType; ?>"><?php echo $statusMsg; ?></div>
</div>
<?php } ?>
<div class="row">
<div class="col-md-12 head">
<h5>Images</h5>
<!-- Add link -->
<div class="float-right">
<a href="addEdit.php" class="btn btn-success"><i class="plus"></i> New Image</a>
</div>
</div>
<!-- List the images -->
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th width="5%"></th>
<th width="12%">Image</th>
<th width="45%">Title</th>
<th width="17%">Created</th>
<th width="8%">Status</th>
<th width="13%">Action</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($images)){
foreach($images as $row){
$statusLink = ($row['status'] == 1)?'postAction.php?action_type=block&id='.$row['id']:'postAction.php?action_type=unblock&id='.$row['id'];
$statusTooltip = ($row['status'] == 1)?'Click to Inactive':'Click to Active';
?>
<tr>
<td><?php echo '#'.$row['id']; ?></td>
<td><img src="<?php echo 'uploads/images/'.$row['file_name']; ?>" alt="" /></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['created']; ?></td>
<td><a href="<?php echo $statusLink; ?>" title="<?php echo $statusTooltip; ?>"><span class="badge <?php echo ($row['status'] == 1)?'badge-success':'badge-danger'; ?>"><?php echo ($row['status'] == 1)?'Active':'Inactive'; ?></span></a></td>
<td>
<a href="addEdit.php?id=<?php echo $row['id']; ?>" class="btn btn-warning">edit</a>
<a href="postAction.php?action_type=delete&id=<?php echo $row['id']; ?>" class="btn btn-danger" onclick="return confirm('Are you sure to delete data?')?true:false;">delete</a>
</td>
</tr>
<?php } }else{ ?>
<tr><td colspan="6">No image(s) found...</td></tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</body>
</html>
最终的结果是表单actionname、文本区域和概要文件上传内容显示在profile.php文件的gallery crud上方。我该怎么做
谢谢:在进行任何输出之前,应该调用Header函数 请记住,在发送任何实际输出之前,必须调用header,无论是通过普通HTML标记、文件中的空行还是从PHP 当您呼叫headerLocation时。。。输出部分html后,它将无法工作
您应该尝试移动带有标题的逻辑。。。转到文件的顶部。当您重定向到另一个页面时,您必须在页面中携带$\u POST的值,否则您将获得空值。你可以随身携带。 您可以在重定向到另一个页面的语句之前执行此操作,如
$_SESSION['post_data']=$_POST;
header('Location:profile.php'); exit;
现在您已经在会话中发布了数据。谢谢您的建议!!!谢谢你的建议!!!