Reputation: 49
I ran into a trouble yesterday and I don't know how to fix this problem. I have a form
<form action="#" method="POST" target="_self">
<input type="text" name="name">
<input type="Submit" value="submit">
</form>
and the .php code is simple: < ?php if (isset($_POST['name'])) echo $_POST['name']; ? >
the problem is that after I write something in the "name" field and click "submit" all I get is " Notice: Undefined variable: n in G:\wamp\www......" ...but, if i change to action="somefile.php" I get the result I need... it works...
Do you what the problem may be?
Upvotes: 1
Views: 998
Reputation: 399
Why do you want to send something to "#"? If send something to the same page, I prefer use action="<?php echo $_SERVER['PHP_SELF']; ?>"
, in additional if you want send something to the same page without refreshing, try using AJAX
.
Upvotes: 0
Reputation: 133
action="your_page.php"
your_page.php is where to send the form-data when the form is submitted.
Possible values: An absolute URL - points to another web site (like action="http://www.example.com/example.htm") A relative URL - points to a file within a web site (like action="example.htm")
Upvotes: 0
Reputation: 3813
You can either change the action to
action=""
or remove it entirely, which will default to posting to the same page.
Upvotes: 2