Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, December 25, 2015

php, form using the same page after submittion

php, form using the same page after submittion


I'm wondering what's the easiest way to make let's say a form with user/pass and submit button with php but after you submit it goes back to the same page instead of going to another php page.

I'm thinking of if/else statement but a bit confused how to set it after lots tries but still not getting the result wanted

weird I did all those you guys said before I posted..but...>.<" let's say just something simple like this...

but I also want to set if nothing is entered then sumbit is clicked there'll be an error....should be something easy but I don't know why I can't seem to figure it out

";      echo "
"; echo "
"; echo ""; } if(empty($_POST["user"])) { userPass(); } if(!(empty($_POST["user"]))) { if($_POST["user"] == "comp") { echo "Welcome comp"; } else { echo "Wrong user"; } } ?>

Answer by codefreak for php, form using the same page after submittion


if current page is index.php, use index.php in form tag as value of action.

like this:

u can check for submitted form by putting:

if(isset($_POST)){  ...  }  

at top of page

Answer by yourdeveloperfriend for php, form using the same page after submittion


You can define in the form submission:

You can also leave action out altogether, and it will automatically post/get to that same file.

Answer by Techie for php, form using the same page after submittion


Just use below syntax

  

You can check whether post is set using isset() method.

Answer by Boris for php, form using the same page after submittion


This is a code that I created to control learning the required input fields satisfy the requirements. when this is so, the data will be sent to the database. if it does not meet the requirements, there will be a message may be shown at the top of the page

if (!isset($_POST['submitform'])) {
} else {

$_SESSION['firstname'] = $_POST['firstname'];  $_SESSION['lastname'] = $_POST['lastname'];  $_SESSION['email'] = $_POST['email'];  $_SESSION['mobile'] = $_POST['mobile'];  $_SESSION['telephone'] = $_POST['telephone'];  $_SESSION['place'] = $_POST['place'];  $_SESSION['street'] = $_POST['street'];  $_SESSION['housenumber'] = $_POST['housenumber'];  $_SESSION['gender'] = $_POST['gender'];    if (empty($_POST['firstname']) or empty($_POST['lastname']) or empty($_POST['email']) or empty($_POST['mobile'])or empty($_POST['telephone']) or empty($_POST['place'])  or empty($_POST['street']) or empty($_POST['housenumber']) or !isset($_POST['gender']))  {      echo "Sending denied";  }  else  {             require 'database.php';        header('Location: succes.php');  }  

?>

I hope this is helpful information for you

Answer by Axel Capaert for php, form using the same page after submittion


";      echo "
"; echo "
"; echo ""; } if(empty($_POST["user"])) { userPass(); } *if(!(empty($_POST["user"])))* { if($_POST["user"] == "comp") { echo "Welcome comp"; } else { echo "Wrong user"; } } ?>

This part of your code is wrong, you should type : if(!empty($_POST["user"]))

Answer by forresthopkinsa for php, form using the same page after submittion


The other answers are right; you only need to send the user back around to your current page in the "action" property. You can test to see if they did so using "isset".

Something that I'm surprised hasn't been mentioned yet is that your input is not being sanitized, and you're setting yourself up for disaster. Huge injection vulnerability in your action attribute:

$_SERVER['PHP_SELF']  

If you don't sanitize this, then someone can just modify the URL that they see and your poor PHP script won't know any better than to process that as your SELF constant.

In other words, you absolutely must use an htmlspecialchars() function to html-encode that parameter. With that, your action should look more like htmlspecialchars($_SERVER['PHP_SELF']).


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.