PHP form submit on same page

How to do PHP form submit on same page. On submitting the form stay on same page.

In this article we’ll discuss php form submit on same page. There are two ways to submit a form using php, either on the same page or to a php script. To submit a form on the same page, just specify

Syntax :

<?=$_SERVER['PHP_SELF'];?>

inside the action attribute.

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
//form elements
</form>

There will be a confusion that after self submitting how to do the code part, for that just check the form submited or not. then do the codings inside the if condition. Check the following example,

Full Code :

<?php
if(isset($_POST['submit']))
{
    //your php scripts
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Base 64 image Upload</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
    <div class="row">
	<div class="col-md-4">
	   <form action="<?=$_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
		<!-- Your form elements -->
		<input type="submit" name="submit" value="Submit" class="btn btn-sm btn-info">
	   </form>
	</div>
   </div>
</body>
</html>

Included bootstrap css https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css to style the form.

For other php solutions please check php

Related Posts

forest fire

Forest Fire – Techgig, All testcases passed. Challenge #1

Forest FireĀ (100 Marks) Challenge 1: Forest fire You are camping in a forest area at night. You are living with the forest officers to experience their challenges…

the magic wand

The Magic Wand – TechGig PHP answer, all test cases passed. Challenge #2

The Magic Wand – TechGig PHP answer – all testcases passed The Magic Wand (100 Marks) You are a wizard who possesses the magic wand that can be…

PHP interview Questions and Answers

What is PHP? Answer: PHP stands for Hypertext Preprocessor. It is a widely used server-side scripting language primarily designed for web development. PHP code is embedded within…

install php

A Step-by-Step Guide on How to Install PHP

Install PHP : A Step-by-Step Guide on How to Install PHP Introduction: PHP is a widely used server-side scripting language that powers countless websites and web applications….

what is php

What is PHP? Understanding PHP: The Powerhouse of Web Development

Introduction: What is PHP? Understanding PHP: The Powerhouse of Web Development: In the world of web development, PHP stands tall as one of the most widely-used and…

php form

Complete Php form example

Here we are going to check how to create a php form and insert its values to database table. In this example we will be submitting the…

Leave a Reply

Your email address will not be published. Required fields are marked *