Redirect issue

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 11
Joined: Fri Feb 14, 2020 7:28 pm

Tue Oct 13, 2020 12:15 pm

Hello all!!

I got an image gallery crud script and decided to make the edit image page an edit profile page. My issue is what I added doesn't redirect back to profile page. Here is my code :

Code: Select all

// Start session

// 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
    $statusMsg = $sessData['status']['msg'];
    $statusMsgType = $sessData['status']['type'];
<!DOCTYPE html>
<html lang="en-US">
<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">
  .form {
    width: 300px;
    margin: 0 auto;

<div class="container">
	<h1>Image Gallery</h1>
	<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>

  <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 class="nav-item">
      <li class="nav-item">
       <li class="nav-item">
    <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 class="form-inline my-2 my-lg-0">
      <a href="profile.php" class="profile">Profile</a>
 <form class="form-inline my-2 my-lg-0">
      <a href="useaccount.php?logoutSubmit=1" class="logout">Logout</a>
  <?php //from   ww  w  .j  a va2  s .c om
    if ( isset( $_POST["submitButton"] ) ) { 
      // (deal with the submitted fields here) 
      header( "Location: profile.php" ); 
    } else { 
    function displayForm() { 
    <!DOCTYPE html5> 
        <form action="profile.php">
  <label for="img">Select image:</label>
  <input type="file" id="img" name="img" accept="image/*">
  <input type="submit">
        <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">
            <input type="submit" name="submitButton" id="submitButton" value= "Send Details" /> 


	<!-- Display status message -->
    <?php if(!empty($statusMsg)){ ?>
    <div class="col-xs-12">
        <div class="alert alert-<?php echo $statusMsgType; ?>"><?php echo $statusMsg; ?></div>
    <?php } ?>
	<div class="row">
        <div class="col-md-12 head">
            <!-- Add link -->
            <div class="float-right">
                <a href="addEdit.php" class="btn btn-success"><i class="plus"></i> New Image</a>
        <!-- List the images -->
        <table class="table table-striped table-bordered">
            <thead class="thead-dark">
                    <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>
					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';
                    <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>
                        <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>
                <?php } }else{ ?>
                <tr><td colspan="6">No image(s) found...</td></tr>
                <?php } ?>
End result would have the form action(name, text area and profile upload) content to show up before the gallery crud on the profile.php file. How do I do this?

Thank you :)
Post Reply