1
votes

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?

3
# means go to top of the page without refreshing, so your form will not submit for sure, if you want to submit to the same page use action="" - CodeBird
I read on this site that action="" is dangerous and should not be used. Is this correct ? - Vali Ploiesti
someone who wrote it has no clue - Your Common Sense
@ValiPloiesti: Read Difference between action=“” and action=“#” in HTML and the link in the accepted answer. - Amal Murali
@ValiPloiesti it has nothing to do with dangerous, action="" is same as action="something.php" don't believe everything you read, do some research... Some people have no clue as Your Common Sense said - CodeBird

3 Answers

2
votes

You can either change the action to

action=""

or remove it entirely, which will default to posting to the same page.

0
votes

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")

0
votes

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.