Click here to Skip to main content
15,038,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want my form to be submitted, after submitting that values it should redirect to the form and display the values.

What I have tried:

<?php include ( "./inc/connect.inc.php" );?>
<!DOCTYPE html>
<html>
<head>
<title>Add Content</title>
</head>
<body>
<?php include ( "./inc/header.inc.php" );?>
<div id="mainContainer">
<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>
<?php include ( "./inc/footer.inc.php" );?>




And this is my insertcontent.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);
// Check if image file is a actual image or fake image
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 file size
if ($_FILES["fileToUpload"]["size"] > 500000)
{
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" )
{
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$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())");
}
?>
Posted
Updated 12-Aug-17 10:48am
v2

1 solution

You can just echo, after your insert query.

PHP
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())");

echo " ".$_GET["contentCategory"]." ".$_GET["contentTitle"]." , You Have Successfully Inserted !!";

}
   
Comments
Member 13074487 12-Aug-17 17:07pm
   
I've tried it but it's showing
Notice: Undefined index: contentCategory

and for the contentTitle also....
Kistlak 13-Aug-17 3:46am
   
Just edit as below..

echo " ".$_POST["contentCategory"]." ".$_POST["contentTitle"]." , You Have Successfully Inserted !!";
Member 13074487 13-Aug-17 5:00am
   
thanks.. it's working...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900