This is simple and should work but doesn't, so I'm obviously derping pretty hard somewhere. The uploaded file name should print after form submission.
<?php
if (isset($_POST["submit"])) {
$name_of_uploaded_file = $_FILES['uploaded_file1']['name'];
print($name_of_uploaded_file);
}
?>
<form id="contactform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
<td>
<table>
<tr>
<td>
Attach Logo:
</td>
<td>
<input type="file" id="uploaded_file1" name="uploaded_file1" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<input name="submit" id="submit" type="submit" value="Send" />
</td>
</tr>
</table>
</form>
You need the content encoding type set on your form open tag.
<form enctype="multipart/form-data" action="uploader.php" method="POST">
Related
I'm a PHP beginner & have a question xd
Whenever I click on the submit button, the data of the last user in the PHP table are changed.
Could somebody check on it?
<?php
foreach ($db->results() as $unpaid){
?>
<form method="POST">
<tr><td>
<?=$unpaid->id?>
<input type="hidden" name="user" value="<?=$unpaid->id?>">
</td>
<td><?=$unpaid->username?>
</td>
<td><?=$unpaid->bitcoinadress?></td>
<td><?=$unpaid->points?></td>
<td><?=$unpaid->requestdate?></td>
<td><?=$unpaid->status?></td>
<td>
<input type="submit" class="btn btn-warning" name="submit" value="Submit" /><br/>
</td>
</tr>
<?php } ?>
<?php
if(isset($_POST['submit']))
$id = $POST_['user'];
$db->update("payment_request", $id, ["status"=>"Paid"]);
?>
</form>
</table>
You can't put a <form> around a <tr>. You need to put the form inside one of the <td> tags.
<table>
<?php
foreach ($db->results() as $unpaid){
?>
<tr>
<td> <?=$unpaid->id?> </td>
<td><?=$unpaid->username?> </td>
<td><?=$unpaid->bitcoinadress?></td>
<td><?=$unpaid->points?></td>
<td><?=$unpaid->requestdate?></td>
<td><?=$unpaid->status?></td>
<td>
<form method="POST">
<input type="hidden" name="user" value="<?=$unpaid->id?>">
<input type="submit" class="btn btn-warning" name="submit" value="Submit" /><br/>
</form>
</td>
</tr>
<?php } ?>
<?php
if(isset($_POST['submit']))
$id = $POST_['user'];
$db->update("payment_request", $id, ["status"=>"Paid"]);
?>
</table>
<div id="option-action">
<form action="{{ path('lab_univer_cpanel') }}" method="post" enctype="multipart/form-data" >
<table>
<tr>
<td><label>Titre</label></td>
<td><input type="text" id="titre" name="titreNews"></td>
<td></td>
</tr>
<tr>
<td><label>Image</label></td>
<td><input type="file" id="image" name="image" /></td>
<td></td>
</tr>
<tr>
<td><label>Contenue</label></td>
<td><textarea name="content" ></textarea></td>
<td></td>
</tr>
<div class="submit">
<input type="submit" name="addNews" value="+" class="addbtn">
</div>
</table>
</form>
</div>
I don't find the file image in the controller
This is the code to get request :
if ($req->request->get('addNews')) {
$titre = $req->request->get('titreNews');
$content = $req->request->get('content');
$membre = $em->getRepository('LabUniverBundle:Member')
->findOneBy(array('nom'=>'user'));
$image = $req->files->get('image');
print_r($image);
The result is a blank page !
I test with an other form like that :
<form action="{{ path('lab_univer_cpanel')}}" method="post" enctype="multipart/form-data" >
<input type="file" name="image" />
<input type="submit" value="send" name="checkUpload" />
</form>
It works !!!
I've been looking through the site and going over pointers on similar problems but none have seemed to work for me. I'm a wee bit stuck, hoping someone can point out my stupidity.
I created a basic form to test as my main site was giving me problems. There is no error checking or filtering for malicious code, it's just a test to figure out why it won't work.
I can't retrieve any data from a textarea.
All other types work, text, number, etc... all fine.
Here is my basic form, can anyone see the error of my ways?
<?php
require_once('header.php');
if(isset($_POST['submit']))
{
echo "<br>single line comment: " .$_POST['singlelinecomment'];
if (!isset($_POST['comments']))
{
echo "<br>nothing in textarea data, move along, move along";
}
else
{
$comments = $_POST['comments'];
echo "<br>comments: ". $comments;
}
}
?>
<form name="conversation-form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<input type='text' name="singlelinecomment">
</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="50" form="conversation-form" name="comments"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit" /><br>
</td>
</tr>
</table>
</form>
form="conversation-form" remove it from textarea, it's the main cause.
Plus, you don't need this name="conversation-form" in <form>, unless you want to use it for CSS purposes, then use id="conversation-form" or class="conversation-form"
<textarea rows="20" cols="50" form="conversation-form" name="comments"></textarea>
^^^^^^^^^^^^^^^^^^^^^^^^ remove it
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<input type='text' name="singlelinecomment">
</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="50" name="comments"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit" /><br>
</td>
</tr>
</table>
</form>
This question already has answers here:
Checking if form has been submitted - PHP
(9 answers)
Closed 8 years ago.
I am looking to have the results of a query to be posted on the same HTML page that data is entered into. I believe that this can be done with the isset() command, but I don't truly understand what it does and what is telling my page to go to a new php url to give me my table of data.
<html>
<body>
<form action="results.php" method="post">
<table border="0">
<td align="center"><head>Orders</head>
</tr>
<tr>
<td>Enter order number:</td>
<td align="center"><input type="text" name="enter" size="3" maxlength="3"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
This is my current code. Does the
<form action="results.php" method="post">
Line tell the code to post to a new page? Does
if(isset($_POST))
go somewhere in the code in my html file or in my results.php file?
If your form is on index.php page than first thing to do is to change action="results.php" to action="index.php" so you are not redirected to result.php page. Than you can do something like this:
<html>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "Order number - " . $_POST['enter'];
}
?>
<form action="index.php" method="post">
<table border="0">
<td align="center"><head>Orders</head>
</tr>
<tr>
<td>Enter order number:</td>
<td align="center"><input type="text" name="enter" size="3" maxlength="3"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
And if you want also fill form fields with entered value than you could do this:
<html>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "Order number - " . $_POST['enter'];
}
?>
<form action="index.php" method="post">
<table border="0">
<td align="center"><head>Orders</head>
</tr>
<tr>
<td>Enter order number:</td>
<td align="center"><input type="text" name="enter" size="3" maxlength="3" value="<?php echo isset($_POST['enter'])?$_POST['enter']:'';?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
If you want the same file to show the results,
you have to rename the .html of the current file to .php
use <form method="post" action="<?php echo $PHP_SELF;?>"> instead of <form action="results.php" method="post">
now you add if(isset($_POST)) somewhere in the same file
you can add html code as usual to a .php file but you cannot add php code to a .html file
you can use:
if(isset($_POST['enter']))
also if you want to execute the output when "enter" field doesn't have a blank value, then you can use :
if(isset($_POST['enter']) && $_POST['enter']!="")
also keep the form action value to the same page like this:
<form action="" method="post">
OR
<form action="<?php print($_SERVER['PHP_SELF']); ?>" method="post">
Ok so im making a login system and for some reason when typed like this im getting issues with it posting without an echo or print and the following script the displays itself help anyone.
<?PHP $form = '
<form method="POST" action="login.php">
<table>
<tr>
<td>Username:<td>
<td><input type="text" name="user"><td>
</tr>
<tr>
<td>Password:<td>
<td><input type="password" name="password"><td>
</tr>
<tr>
<td><td>
<td><input type="submit" name="loginbtn" value="Login"><td>
</tr>
<tr>
<td>Register<td>
<td>Forgoten Password<td>
</tr>
</table>
</form>'
;
?>
<?php //Some PHP Code if necessary
if(true) { //Any html between this brace and the next brace will be included
?>
<form method="POST" action="login.php">
<table>
<tr>
<td>Username:<td><td>
<input type="text" name="user">
<td>
</tr>
<tr>
<td>Password:<td><td>
<input type="password" name="password">
<td>
</tr>
<tr>
<td><td><td>
<input type="submit" name="loginbtn" value="Login">
<td>
</tr>
<tr>
<td>Register<td><td>Forgoten Password<td>
</tr>
</table>
</form>
<?php
} //End of if statement.
else { //This won't be shown, because the if statement is always true
?>
<div>
This is not displayed
</div>
<?php
}
?>