Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Form with process on same page?

Tags:

forms

php

I've created a form on my page and from the tutorials im following it says I have to have a second page with all the php processing in, is it not possible to keep the php on the same page and when the user hits submit the form is sent?

Why isnt this working on my process page? It doesnt echo anything :S

<?php 
$kop = mysql_real_escape_string($_POST['severity']);
$loc = mysql_real_escape_string($_POST['location']};
$summary = mysql_real_escape_string($_POST['summary']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);

echo $kop;
echo $loc; 
echo $summary; 
echo $name; 
echo $email;
?>
like image 474
Ahmed Deloitte Avatar asked Dec 03 '22 02:12

Ahmed Deloitte


1 Answers

You can check in the same file if the submit button is pressed. (http://pastebin.com/8FC1fFaf)

if (isset($_POST['submit'])) 
{ 
    // Process Form
}
else
{
    // Show Form
}

Regarding form checking, you can save the user input, and if one of their data is unvalid you can echo the old data back and show the form again.

edit: As PeeHaa stated, you need to leave the action blank though ;)

like image 74
Wouter van Tilburg Avatar answered Dec 27 '22 10:12

Wouter van Tilburg