提交后如何将表单重定向到同一页面? [英] How do I redirect a form after submission to the same page?

查看:240
本文介绍了提交后如何将表单重定向到同一页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的表单在提交后应该重定向到表单并显示值后提交。我尝试了很多东西......但是没有运气......
所以我决定在这里发帖。它应该像大多数的编辑字段,存储的值或提交的值应该出现。

这是我的代码:

I want my form to be submitted, after submitting that values it should redirect to the form and display the values. I've tried many things... but no luck yet... So I've decided to post here. It should be like most of the edit fields, the stored value or the submitted value should appear.
This is my code:

<form method="post" name="contentUpload" action="insertContent.php" enctype="multipart/form-data">    
    <table>
        <tr id="small">
            <td>Category</td>
            <td>
                <select name="contentCategory">
                    <<option value="1">World</option>
                        <option value="2">Health/Env/Scn</option>
                        <option value="3">Travel</option>
                </select>
            </td>
        </tr>
        <tr id="small">
            <td>Title</td>
            <td>
                <input type="text" name="contentTitle" size="80">
            </td>
        </tr>
        <tr id="small">
            <td>Writer</td>
            <td>
                <input type="text" name="writer" size="80">
            </td>
        </tr>
        <tr id="small">
            <td>Upload Picture</td>
            <td>
                <input type="file" name="fileToUpload" id="fileToUpload">
            </td>
        </tr>
        <tr>
            <td id="small">Display Mode</td>
            <td required>
                <input type="radio" name="status" value="Online" /> Online
                <input type="radio" name="status" value="Offline" /> Offline
            </td>
        </tr>
        <tr>
            <td id="small">Final Submission</td>
            <td>
                <input type="submit" name="submitContent" value="Update">
                <input type="reset" name="resetContent" value="Reset">
            </td>
        </tr>
    </table>
</form>
</div>

这是我的addcontent.php

this is my addcontent.php

<?php include ( "./inc/connect.inc.php" ); ?>
<?php
session_start();
$target_dir = "new/Images/";
$file_name = $_FILES["fileToUpload"]["name"];
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submitContent"])) 
{
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) 
{
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} 
else 
{
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) 
{
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} 
else 
{
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) 
{
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} 
else 
{
echo "Sorry, there was an error uploading your file.";
}
}
if (isset($_POST['submitContent']))
{
$eid = $_SESSION['employeeId'];
$contentCategory = $_POST['contentCategory'];
$contentTitle = $_POST['contentTitle'];
$contentWriter = $_POST['writer'];
$displayMode = $_POST['status'];
$query = mysqli_query($con,"INSERT INTO contentdetails(employeeId,contentCategory,contentTitle,contentWriter,photo,displayMode,published_on) 
VALUES('$eid','$contentCategory','$contentTitle','$contentWriter',
'$file_name','$displayMode',NOW())");
}
?>


推荐答案

在您的表单标记中留下action =标记空。

in your form tag leave the action="" tag empty.

<?php 
    // Remove session_start() from this file. It should be before any html.
    include 'insertContent.php';
    if (isset($_POST['submitContent'])) {
        foreach ($_POST as $p) {
            echo $p . "<br>";
        }
    }
?>
<form method="post" name="contentUpload" action="" enctype="multipart/form-data">

这篇关于提交后如何将表单重定向到同一页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆