I would like to use the data entered in the html form and insert into MYSQL. I have a separate php (cus.php). but nothing is happening with current code I have
at the moment when I click "register" I'm nav to the php file. Thank you
You forgot the most important thing about an HTML form: the <form> tag.
You have to wrap the whole form (all inputs) which should be submitted when clicking like this:
<form method="POST" action="cus.php">
...
</form>
This will send all inputs to cus.php and make them available there as variables $_POST['input_name']. You can alternatively use GET as the method (and then use the $_GET array instead).
Edit: Didn't see it, you actually do have a form tag. However it's missing the target file in its action attribute.
First, see DCoder's comment. It's the most important.
Change:
<form action="" method="seller">
To:
<form action="cus.php" method="post">
Does that fix it?
Try to do this
FORM action="your script" method="Post"
Related
I was doing an application form and the form is not working. When I click the submit button it doesn't even run the if statement to POST the variables.
My form tag looks like this:
<form method="post" enctype="multipart/form-data">
My submit button looks like this:
<button name="submeter" type="submit" class="btn btn-gfort">Submeter</button>
And the if statement in my form looks like this:
if(isset($_POST['submeter'])) {
I even tried to run a JS alert just to see if it actually enters the if statement but it doesn't. No console errors as well.Any help is appreciated
Have you added method="post" to the <form>-tag?
Well your codes looks fine. it seems you are submitting the form using post method on some php file. Please share the complete form element and the codes of the target file that you have defined in the action attribute of form tag.
the submit button sends the data to server and there you can process the data using any server side scripting language. your codes must look something like
<form action="process.php" method = "post">
<!-- your form controls -->`
<button name="submeter" type="submit" class="btn btn-gfort">Submeter</button>
</form>
then create another file on same location where html/php file containing this form is saved with name process.php, in which you can use following codes.
if(isset($_POST['submeter'])) {
// php codes
}
in case you want to subimt the form on the same page. make sure your file is php use action="#" in form tag and place the file of your webserver as you can not run php files directly from your filesystem but you need to run it through your webserver
I am wondering if there is a way to declare a Global HTML- tag, that gets submittet with each form that gets called.
I mean something in the way like this:
<input type="hidden" name="x" value="200">
<form action="test.php" method="POST" enctype="multipart/form-data">
#Some Form-Stuff
</form>
<form action="test.php" method="POST" enctype="multipart/form-data">
#Some more Form-Stuff
</form>
And in both of these Forms, when a Submit is being made, there is supposed to be the Global hidden Input-Tag that gets delivered with the rest.
I already tried it and it didnt work, but I wonder if there is just something that is missing or if there is a similar or better way to accomplish this.
Would appreciate your help.
EDIT:
What I want in my current Project is to let the User <SELECT> an option that represents like an Folder in which there will be displayed data that is inside that folder.
I dont want the User to have to Select the Folder again after each click and the folder has to be submitted every time to the php-script so that it can handle data accordingly to the folder selected.
My Question in this case however still remains on wether you can or cannot make a <input> tag global or not, if it´s permanent or not doesnt matter.
Either include the following in your form
<input type='hidden'>
It is great for passing values without much code.
Or set it as a cookie/session variable as required.
Let's say I have a form on my website homepage: www.mysite.com
Now, the form tag looks like this:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
...
</form>
When that form submits, it does everything it's suppose to. But it also reloads the page with the full filename and extension. So the user will now find the URL in the address bar is: www.mysite/index.php
Is there a way to make the form fire to the same page without adding this extension?
There may be situations where the form is as an include in a footer, so I cann't be specific about the page the form needs to fire to, hense the PHP_SELF code.
That's because $_SERVER['PHP_SELF'] refers to the actual filename of the current script.
Try this:
<form action="" method="post">
An empty action will post back to the current URL.
Try setting the action to #:
<form action="#" method="post">
...
</form>
The # refers to the current page.
Try changing action to #, this post to the current page.
Edit: Mike beat me to it.
Edit 2: It looks like you can leave out the action all together and it will default to the same page.
Edit 3: Mike beat me to that one too.
I've seen <form> opening tags that look like this:
<form action="<?= $_SERVER['REQUEST_URI'] ?>">
Does the action attribute here make any sense?
Wouldn't the form behave the same way without it?
You should always include the action attribute in your form tag if you want a good valid markup (which you should). It is a required attribute (though most browsers will work around it if you don't and assume action="").
Using:
<form action="" method="post">
...will work and just use the current page as the action page.
http://www.w3schools.com/tags/tag_form.asp
Hope this helps.
If you set it to blank you get the same effect (which is what I prefer)
<form action="" method="post"> ....
Yes, you have to include action attribute within <form> tag. See some documentation.
However, you do not need to pass current URI, you can add empty action attribute like that:
<form action="">
...
</form>
and then the form will be sent to the current location (current URI).
I'm programming a webpage and in my index, I have two forms.
The 1st is for the login:
<form method="post" action="login.php">...</form>
The 2nd is for search:
<form method="post" action="search.php">...</form>
My problem is that when I submit the search form, it works as if the action is targeting login.php. When I see the source code, the tag <form method="post" action="search.php"> doesn't appear.
The most probable cause of the problem is incorrectly nested forms or missing closing form for login form. Check the generated HTML for the validity of the HTML and if not post the generated HTML so that we can help you debug.
It is hard to tell without seeing the complete page, but I would guess that you have one form inside the other — which is forbidden. You cannot nest forms.
Turns out I didn't really close the form tags, I typed <form> instead of </form>. Sorry.