Reputation: 21
So pretty much this is my code. It's not generating any sort of post. Is there some reason why this is occuring? It's rather annoying. And is getting on my nerves.
I've been trying to de-bug this for about 30 minutes now. And I've tried numerous things. Is it because of it not actually posting the values? Or is it just not reading them properly?
echo $_POST["sntype"];
And here is the form code:
$htmloutput1 = '<html>
<body>
<form name="sntype" action="site.php" method="post">
<select>
<option value="1">Please Choose...</option>
<option value="Elect">Electronics</option>
<option value="Food">Food</option>
<option value="Other">Other</option>
<input type="submit" value="Submit">
</form>
</select>
</body>
</html>';
echo $htmloutput1;
echo $_POST["sntype"];
Upvotes: 0
Views: 80
Reputation: 26066
The </select>
is placed outside of the <form>
and the <input>
is inside the <select>
as a result.
<form name="sntype" action="site.php" method="post">
<select>
<option value="1">Please Choose...</option>
<option value="Elect">Electronics</option>
<option value="Food">Food</option>
<option value="Other">Other</option>
<input type="submit" value="Submit">
</form>
</select>
How about trying this instead:
<form name="sntype" action="site.php" method="post">
<select>
<option value="1">Please Choose...</option>
<option value="Elect">Electronics</option>
<option value="Food">Food</option>
<option value="Other">Other</option>
</select>
<input type="submit" value="Submit">
</form>
EDIT Also, what do you expect to get from echo $_POST["sntype"];
? That is simply the name of the form: sntype
. That is not the value of the <select>
. And <select>
has no name. So why not set this:
<form name="sntype_form" action="site.php" method="post">
<select name="sntype">
<option value="1">Please Choose...</option>
<option value="Elect">Electronics</option>
<option value="Food">Food</option>
<option value="Other">Other</option>
</select>
<input type="submit" value="Submit">
</form>
I changed the name of the <form>
to be sntype_form
and set <select>
to now be <select name="sntype">
so the name is now sntype
.
Upvotes: 2
Reputation: 3385
Ok so lots of problems with your code.
Try the following:
<?php
if(isset($_POST["sntype"])){ //if sntype was submited
echo $_POST["sntype"];
}
else{ //otherwise display form
?>
<html>
<body>
<form action="" method="post">
<select name="sntype">
<option value="1">Please Choose...</option>
<option value="Elect">Electronics</option>
<option value="Food">Food</option>
<option value="Other">Other</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php } ?>
Issues with your code
FORM
tagname
attributeUpvotes: 1