The submit form does not seem to pass along the uploaded file. The code is supposed to display "array" when a file is uploaded. Nothing happens when submit is pressed
<?php
$conn = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db ('coop',$conn);
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file,"r");
while(($fileop = fgetcsv($handle,1000,"|")) !== false)
{
echo $fileop;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>
</head>
<body>
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="file" name="file" />
</form>
<br />
<input type="submit" name="submit" value="submit">
</body>
</html>
Your <form> </form> tag should wrap all elements of the form. Like the following:
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="file" name="file" />
<br />
<input type="submit" name="submit" value="submit">
</form>
Your submit is outside of the form tags, Fix your HTML and the posting should work.
Related
So the goal is to take the input from a form append it to the end of the URL and then return the HTML from that page.
I am not entirely sure how to take the forms value (in this case $2) and attach it to the URL.
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="$2" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php $html=file_get_contents("http://www.metar.mysite.net/metar?id=$2")?>
<?php echo $_POST ["$html"];?>
</body>
</html>
On submit any input from a form with method="POST" will be stored in the $_POST global. You can access it from there and append it to your URL string.
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="iacoCode" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($_POST["iacoCode"])) {
$html = file_get_contents("http://www.metar.mysite.net/metar?id=" . $_POST["iacoCode"]);
echo $html;
}
?>
</body>
</html>
Using the IF statement to check if it is set will prevent it from loading the URL with no variable.
The way we extract data via php from a form is like below
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="$2" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php $html=file_get_contents("http://www.metar.mysite.net/metar?id=$_POST['$2']")?>
<?php echo $_POST ["$html"];?>
Im trying to upload a file through a form to my php server and then display the name of the file. ATM I'm getting an error when I'm trying to submit the form:
Objekt was not found! Error 404
<html>
<body>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="file" size="35">
<br>
<br>
<input type="submit" value="Upload" name="submit">
</body>
</html>
<?php
header('Content-type: text/plain');
if(isset($_FILES["file"])){
$file = $_FILES["file"];
echo("File: ".$file);
}
?>
if you want to upload/do any operation on same file then remove action from form. then change your code as below to echo file name
<html>
<body>
<form method="post" enctype="multipart/form-data" >
<input type="file" name="file" size="35">
<br>
<br>
<input type="submit" value="Upload" name="submit">
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if(isset($_FILES["file"])){
$file = $_FILES["file"]["name"];
echo "File: ".$file;
}
}
?>
I want to call my function when I click on my submit button.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form name="bfe-form" method="POST" action="index.php">
<label>Input Url</label>
<input name="url" type="text" value="">
<input name="submit" type="button" value="Submit">
</form>
</body>
</html>
<?php
var_dump($_POST);
var_dump($_GET);
if (isset($_POST['submit'])) {
getContent();
}
function getContent() {
$content = file_get_contents($_POST['url']);
return $content;
}
?>
But I get nothing my php just won't be executed.
Your Submit button should be type=submit instead of button.
it will look like this!
<input name="submit" type="submit" value="Submit">
I'm assuming this page is index.php
<input name="submit" type="submit" value="Submit">
Instead of use type button use type submit
I'm trying to upload files to my server but it doesn't work at all. Here is test code:
<?php
echo count($_FILES['upload']['name']);
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
<br>
<input type="submit" value="Upload">
</form>
</body>
</html>
It always prints 0, file upload is enabled on my server.
The problem is that you're not counting the $_FILES['upload'].
Simple fix for your problem
Use:
echo count($_FILES['upload']);
Instead of:
echo count($_FILES['upload']['name']);
Edit:
Remove [] from the input's name.
<?php
echo count($_FILES['upload']);//only this modified//
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
<br>
<input type="submit" value="Upload">
</form>
</body>
</html>
index.php
<html>
<head>
<script type="text/javascript">
function submitForms()
{
document.forms["form-1"].submit();
document.forms["form-2"].submit();
}
</script>
</head>
<body>
<form method="POST" action="form.php" id='form-1'>
<input type="text" name="txt1" />
</form>
<form method="POST" action="form.php" id='form-2'>
<input type="text" name="txt2" />
</form>
<input type="button" value="Click Me!" onclick="submitForms();" />
</body>
</html>
form.php
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Above is my code and when i submit both forms then both text-fields with their value it does not shoe me both text-field values.It only shoe me second text-field value.Please help me quickly.
I think because you try to get the params after sumbit two forms. You have sent the two forms at once and the second has stepped to the first, so the result is the return of the second form.
I think this will be better:
<html>
<head>
</head>
<body>
<form method="POST" action="form.php">
<input type="text" name="txt1" />
<input type="text" name="txt2" />
<input type="submit" value="Click Me!" />
</form>
</body>
</html>
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Sorry for my english