Here's my HTML:
<!DOCTYPE html>
<html>
<head>
<title>This is where we add Party.</title>
</head>
<body>
<form action="viewParties.php" method="post" enctype="multipart/form-data">
PartyList:<br>
<input type="text" name="partylist"><br>
<input type="file" name="pafile"><br><br>
President:<br>
<input type="text" name="president"><br>
<input type="file" name="pfile"><br><br>
Vice President:<br>
<input type="text" name="vicepresident"><br>
<input type="file" name="vpfile"><br><br>
Secretary:<br>
<input type="text" name="secretary"><br>
<input type="file" name="secpfile"><br><br>
<input type="submit" name="submit"><br><br>
</form>
</body>
</html>
Basically what I want to happen is for the POST Method to take both Names and File Locations. But when I print_r($_POST) in another PHP File, it only shows the Names. Does anybody know how to remedy this?
Found it. Turns out I needed, not only to print($_POST) to see what I submitted but also, to print_r($_FILES) to see what files I submitted. I did some tinkering and this is what I found. Hope this helps someone else. =)
Related
I am running into a strange error on a website using multiple PHP scripts. For some reason, every submit button only calls the first PHP script defined rather than the one chosen. I know all of these scripts work and this issue started only recently. Here is the code in question:
<!DOCTYPE html>
<html>
<head>
<title>Embed PHP in a .html File</title>
</head>
<body>
<h2>POV</h2>
<form action="index.php">
<button type="gohome">Return to main form</button>
</form>
<h3>WIP Final results:</h3>
<br>
<?php
include("showdatabasecontents.php");
?>
<form method="post" action="clearFinal.php">
<input type="submit" name="clearFinal" value="Clear Responses">
<form method="post" action="resetFinal.php">
<input type="submit" name="resetFinal" value="Reset ID Count">
<h3>Students names</h3>
<?php
include("showdatabasecontent2.php");
?>
<h3>Add a Student</h3>
<form method="post" action="addstudent.php">
Student Name : <input type="text" name="studentname"><br><br>
<input type="submit" name="addstudent" value="Submit">
</form>
<h3>Delete a student</h3>
<form method="post" action="connect.php">
ID : <input type="text" name="id"><br><br>
<input type="submit" name="removeStudent" value="Submit">
<br>
</form>
</body>
</html>
I have tried changing some of the names for the buttons to make sure there was not a conflict but that did not make any different. Any info on this issue will help, thanks!
try to add an id to each form. and change
<input type="submit" name="" value="">
to
<button type="button" onClick="test()">Submit</button>
example
<h3>Delete a student</h3>
<form id="deleteStudent" method="post" action="connect.php">
ID : <input type="text" name="id"><br><br>
<button type="button" onClick="test()">Submit</button>
<br>
</form>
last add javascript
<script>
function tes(){
document.getElementById('deleteStudent').submit()
}
</script>
You cannot have nested forms. Please close your forms properly and retry
Found the issue, at the advice of Quentin, I used https://validator.w3.org/. I came to the conclusion based on the information I drew that I was missing a closing tag for two form elements. I would mark this as solved but stackoverflow won't let me for two days :(
Was trying to follow a tuitorial online on how to submit data using html to mysql database.
I created 2 php files named index.php and process.php. What i wanted to show was what I typed in inside index.php will show on process.php when I clicked on the button "add employee". But nothing showed up.
Here is what's inside index.php
<!DOCTYPE html>
<html>
<head>
<style>
label{display:inline-block;width:100px;margin-bottom:10px;}
</style>
<title>Add Employee</title>
</head>
<body>
<form method="post" action="">
<label>First Name</label>
<input type="text" name="first_name" />
<br />
<label>Last Name</label>
<input type="text" name="last_name" />
<br />
<label>Department</label>
<input type="text" name="department" />
<br />
<label>Email</label>
<input type="text" name="email" />
<br />
<input type="submit" value="Add Employee">
</form>
</body>
</html>
Here is a Screenshot of the form.
click here for index.php image
Wile here is what's inside the process.php
<?php
print_r($_POST);
This is what shows up
process.php image
Sorry a beginner at this. Hope you guys can help. Thank you!
Maybe you are missing the "action"?
<form method="post" action="/process.php">
You should specify what you need.Somethings like this:
<?php
print_r($_POST['first_name']);
Or use foreach loop to get full array value.
You can go through with fill up action tag so when you submit the form it will go to proccess.php page.
<form method="post" action="process.php">
Have a look at the following code:
<?php
if (isset($_POST['email']))
{
$expertmail=trim($_POST['email']);
echo $expertmail;
$expertfile=$_FILES['upfile']['tmp_name'];
echo $expertfile;
}
?>
<form action="test.php" method="post" name="users" id="users" >
<input name="upfile" id="upfile" type="file" />
<input name="email" id="email" type="text" />
<input type="submit" name="submit_button" id="submit_button" value="ΑΠΟΣΤΟΛΗ" />
</form>
Why 'echo $expertfile' does not display anything?
Thank you
POST Method Uploads gives all the information you need to handle file uploads in PHP. For your case you need: enctype="multipart/form-data":
<form action="test.php" method="post" name="users" id="users" enctype="multipart/form-data">
As Salman A points out, you will also need to check to see if a file was uploaded.
I am using search form with input field something like:
<input type="text" id="s" name="s">
But whenever page is loading, type="text" is getting removed from the source. I am using PHP with Apache server to render the page.
I also even tried with a simple html page with no JS and a simple input form but there also the same thing is happening.
Please anybody suggest any solution.
Update: Example code as requested by Witherwind:
<!DOCTYPE HTML>
<html>
<head>
<title>Input type attribute test</title>
</head>
<body>
<form>
button <input type="button"><br>
checkbox <input type="checkbox"><br>
color <input type="color"><br>
date <input type="date"><br>
datetime <input type="datetime"><br>
datetime-local <input type="datetime-local"><br>
email <input type="email"><br>
file <input type="file"><br>
hidden <input type="hidden"><br>
image <input type="image"><br>
month <input type="month"><br>
number <input type="number"><br>
password <input type="password"><br>
radio <input type="radio"><br>
range <input type="range"><br>
reset <input type="reset"><br>
search <input type="search"><br>
tel <input type="tel"><br>
text <input type="text"><br>
time <input type="time"><br>
url <input type="url"><br>
week <input type="week"><br>
Submit <input type="submit" value="Submit">
</form>
</body>
</html>
Live example: link
I have this problem when I'm using PHP5/HTML on Apache-Tomcat6.
Here's an example for one of the forms I use in my site:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
Whenever I add the 'enctype' attribute to any form; neither the $_FILES['image'] is returned nor the $_POST variables. As long as the 'enctype' is not there, everything (except for the file input of course) works as expected. Can any one guide me please?
You won't be able to post data with a method of get on your form.
In test.html:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
In hello.php:
<?php
print_r($_POST);
print_r($_FILES);
Depending upon your server configuration, this will combine $_GET, $_POST, and $_COOKIE, but you'll still want to post with file inputs.
print_r($_REQUEST);