By now I know to upload file form is using ENCTYPE="multipart/form-data. But when we want to transfer form datat to mysql via php file what should be the enctpe=""?
<form action="process.php" method="POST" name="contactform" onSubmit="return ValidateForm(this); ENCTYPE="multipart/form-data">
Can we use ENCTYPE="multipart/form-data" if not what should i use???
Please answer me
Thanks
You don't need to fill in a form enctype when you aren't using a file upload.
The default value is: "application/x-www-form-urlencoded". (when enctype not provided)
Conclusion: leave empty or use "multipart/form-data" when you need to upload a file.
See: http://www.w3schools.com/tags/att_form_enctype.asp
Basically ENCTYPE is the property of form. This is not necessory to use this property, it is optional.
Related
I need help with my form. There's a mix of input, textarea and file upload that i want to enter into the database..
What do I use in the ? Do I use the normal form attribute :
<form action="" method="">
or
<form enctype="" action="" method="">
Please have it in mind that, I have to do this in a single page, and the picture upload must be done along with other text input.
Thanks for your time.
You must use enctype="multipart/form-data" for file uploading, this will also work fine for non-file upload forms.
You need to set enctype="multipart/form-data" and use method="post" for any form that includes a file input. This won't stop you from including other types of fields.
(The way those fields will be submitted to the server will change, but your form parsing library will deal with the differences automatically, you only need to worry about them if you are parsing the raw input yourself).
<form enctype="multipart/form-data" method="post" action="submit.php">
submit.php being, in this case, the external PHP script that will process your form ( if you decide to use PHP ). But you can name the .php script whatever you like ( e.g. cats.php ).
The uploaded file/image data will be stored inside $_FILES, and all the textfield, textarea, radio buttons, check boxes and other data will reside inside the $_POST superglobal.
When submit.php receives the submitted form you can do all kinds of processing on it such as validating that user has submitted the correct type of file/image, store the file path of the file/image in your local database( client/server or file system based ), and much more.
Make sure to validate user input client side and server side too.
<form enctype="multipart/form-data" action="yourpage.php" method="post">
You'll need the enctype attribute if you want the file upload to work. FYI, a form can contain every field type, including file uploads, and work just fine.
In Classic ASP I had to access my textfield as load.getFileData("textfield")
instead of the standard Request("textfield") when using the enctype="multipart/form-data"
I have a question about the $_FILES global variable in php. When I do a print_r on my files array I get a blank array() 1 displayed (but I have uploaded one file with post from a form on another page). The post variable for upload (upload being the input type = file name) is set to the filename but nothing in Files is set and if I try and call $_FILES['upload']['name'] nothing shows up. What could be causing this? When I submit my form I have a bunch of different fields (text boxes, select boxes, checkboxes, etc.) but that shouldn't effect my file upload right?
Thanks!
Make sure your form tag has the enctype=multipart/form-data attribute set:
<form action="test.php" method="POST" enctype="multipart/form-data">
You need to make sure your form has the enctype attribute, e.g.:
<form method="post" enctype="multipart/form-data">
<input type="file" name="fileUpload"/>
<input type="submit"/>
</form>
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"
I have a form where a user submits the description of an object (including an image) and there is JavaScript that adds an additional set of inputs for +1 object description. When the form is submitted the file information is not stored in $_FILES.
The form tag is <form id="order_form" name="order_form" method="post" action="#">
The file type input is <input type="file" name="order_image[]" />.
print_r($_FILES); returns
array()
Does anyone have an idea as to why this might be happening. I will gladly include any other information that might be pertinent to this question.
Have you set the correct encoding type in your form tag?
<form enctype="multipart/form-data" method="post" action=...>
<form enctype="multipart/form-data" method="POST">
be sure you include enctype
I have a form and the method is set to post on the action page when I use $_POST i dont get the value but if I use $_GET or $_REQUEST I do.
This does not make sense. Could someone just clarify it for me?
The code of the form is
<form action="create.php" method"POST">
Just realized I am missing the = after method.
It sounds like you've misplaced or mistyped the method attribute and your form is defaulting to HTTP GET. The form should look like this:
<form method="post" action="file.html">
What's the method set to in the HTML for your form, eg:
<form method="POST" ...>
In PHP ini file, the default setting GPC (Get, Post, Cookie) and Request array has that in itself. And make sure that you really the the POST in the action attribute.
It looks like you typoed your HTML:
<form action="create.php" method"POST">
should be
<form action="create.php" method="POST">
You're missing an equal sign.
<form action="create.php" method="POST">
your missing equal sign after the method
POST and GET are different methods to transfer form data, they both use different ways to send the entered values to your application and have to be handled differently. PHP uses $_POST for the values submitted by a form with method="post" and $_GET for values submitted by a form without a method or with method="get". $_REQUEST is a combination of $_POST and $_GET.
The easiest to see difference is:
Parameters submitted with GET appear in the adress bar, i.e.
http://example.com/index.php?page=home
passes the key page with the value home to $_GET.
Post parameters do not appear in the adress bar.
Your method attribute is wrong, should be:
<form action="create.php" method="POST">
Hehe :-)
<form action="create.php" method="POST">
Your sloppy way of writing is not good for coding...
The error seems to be the missing "=" :)
BTW, the $_REQUEST variable isn't just a combination of $_POST and $_GET, it's an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. ;)