Reputation: 11
Why does this not work. I have look at many sites and this works I look long time. Fine no no.
Edited code to this it echo pressed when I havent even pressed the button
<form method='POST' name="form1" action="index.php">
Username: <input name="username"><br>
Password: <input name="password"><br>
<input type = 'submit' name = 'submit' value = 'click me'>
</form>
<?php
if (isset($_POST['submit'])){
echo "Pressed button";
}
?>
Upvotes: 0
Views: 56
Reputation: 4506
Your code is running even without closing form tag. But below is the formal way to use form.
<form method='post' action="">
Username: <input name="username"><br>
Password: <input name="password"><br>
<input type = 'submit' name = 'submit' value = 'click me'>
</form>
<?php
if (isset($_POST['submit'])) {
echo "Pressed button";
}
?>
Upvotes: 0
Reputation: 59997
You need summat like
<form method="post" action="myscript.php">
etc
Upvotes: 0
Reputation: 3682
you need to add form tag and in action tag of form give your php page name. Here is index.php but you need to specify your own script name.
<form name="form1" method="post" action="index.php">
Username: <input name="username"><br>
Password: <input name="password"><br>
<input type = 'submit' name = 'submit' value = 'click me'>
</form>
<?php
if (isset($_POST['submit'])){
echo "Pressed button";
}
Upvotes: 1