Jump to content

Recommended Posts

Can someone help a php newbie? Making a post to php but no data posted.

html file contains this:

 

<head>

<title>database connection</title>

</head>

<body>

<form name= "search" action="welcome.php" method="post">

Name: <input type="text" id= "fname" name="fname">

<input type="submit" name="submit">

</form>

</body>

 

php file contains this:

<html>

<head> <title> Handler </title> </head>

<body>

<?php

echo "beginning ";

if(isset($_POST['search'])) {echo "Welcome" . $_POST["fname"];} else {echo "post not set for fname ";}

if($_SERVER['REQUEST_METHOD'] == "POST") { echo "form submitted";}{echo "request method post not set ";}

echo "end";

?>

</body>

</html>

 

output gives me this:

beginning post not set for fname request method post not set end

 

Im using php 5.2. Im running a windows 7 pc with web server configured (iis). I have validated that php is running.

The above text is the entire text for each file.

Link to comment
https://forums.phpfreaks.com/topic/270980-_post-not-working/
Share on other sites

You are using the form name in your $_POST check.

 

Use the name of your button.

 

So instead of

if(isset($_POST['search'])) {echo "Welcome" . $_POST["fname"];} else {echo "post not set for fname ";}

do:

if(isset($_POST['submit'])) {echo "Welcome" . $_POST["fname"];} else {echo "post not set for fname ";}

 

 

--edit--

beaten by someone else.

for the second part of your script, you forgot an 'else', so you get "request method post not set" as well.

 

if($_SERVER['REQUEST_METHOD'] == "POST") { echo "form submitted";}ELSE{echo "request method post not set ";}

Edited by play_
Link to comment
https://forums.phpfreaks.com/topic/270980-_post-not-working/#findComment-1394063
Share on other sites

Also, relying on a submit button's value being passed on form submisison is unreliable. Instead use either a hidden input value or $_SERVER['REQUEST_METHOD'] to check for form submission.

 

This code needs to be tweaked a little. You need to verify that the text input actually has a value being outputting its value.

Link to comment
https://forums.phpfreaks.com/topic/270980-_post-not-working/#findComment-1394080
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.