I have a desktop application passing POST data (text and an image file) onto a PHP file on an Apache Webserver. For some reason the POST data is coming through empty. Does anyone have any idea what could be causing this?
All I am trying for now is to display the POST data using:
<?php print_r($_POST); ?>
But I'm getting nothing. No errors and no data. The strange thing is this works perfectly on my old server - but with my new host the $_POST var is coming through empty so I'm confident it isn't an issue with the app.
The desktop app was built by someone else using Poco to send the HTML Form data so I don't know too much about it but I know if definitely works as it is currently working on my current other webserver.
Weirder still, when I don't attach an image everything works as expected. As soon as an image is attached (<100kb) I get no data whatsoever.
The Poco HTML Form is using multipart/form-data as the encoding type when an file is attached and application/x-www-form-urlencoded when there is no attachment (default).
I'm stumped here and wondering if anyone knows what could be going on or at least what I should be looking to try at?
Thanks in advance.
Edit: I also forgot to mention that it works if I submit it from another webpage without issue.
Double edit: Here is the equivalent of the form in HTML:
<form enctype="multipart/form-data" action="http://DOMAIN.COM/savedata.php" method="POST">
name: <input type="text" name="name" /><br />
email: <input type="text" name="email" /><br />
gender: <select name="gender"><option value="0">Female</option><option value="1">Male</option></select><br />
photo: <input name="photo" type="file" /><br />
<input type="submit" value="Upload File" /></form>
Related
I am trying to have users use an HTML form to input their email addresses but I would like the addresses to go to a word doc or notepad or a text file on the iPad pro they are entering this all on.
I'm trying to figure out the best method to do this as I'm not using a hosted server.
So far this is what I've been using in my HTML file:
<form action="" method="post>
Name:
<input type="text" name="name">
Email:
<input type="email" name="email">
<input type="submit">
</form>
Can you tell me if I need to incorporate PHP or tell me how to do that? I've tried using POST but kept getting 'Post method not allowed' and if I tried to use GET, I would get an internal server error.
Any help would be greatly appreciated!
I have just spent 4 hours researching and nothing has fixed my problem, so here I am. I am trying to design my own little chunk file uploader, and all is working quite well.
I have a main upload page that lets you set a file to upload. It then automatically cuts the first chunk out of the bytes of the file, and puts it into a form, along with some other bits of information:
<form id="hiddenform" name="hiddenform" action="SecretChunkUploader.php" target="iframe" enctype="multipart/form-data" method="post">
<hidden id="Bytes" name="Bytes" value="" />
<hidden id="Pass" name="Pass" value="<?php echo $_POST['Pass'];?>" />
<hidden id="FileName" name="FileName" value="" />
<hidden id="PackageNumber" name="PackageNumber" value="" />
</form>
Every <hidden> has its value correctly sent when the form is submitted through this javascript command:
document.forms["hiddenform"].submit();
The form is submitted to an iframe:
<iframe id="iframe" name="iframe" onload="" style="display:block"></iframe>
When submitted, the iframe navigates to the page specified in the form's action attribute.
Everything works well, except for when the form is received. The page loads, but there is no post data, and the variables for post are not set.
Here is the code for SecretChunkUploader.php:
<?php
echo "Password: ".$_POST["Pass"]."<br/>";
echo "FileName: ".$_POST["FileName"]."<br/>";
echo "PackageNumber: ".$_POST["PackageNumber"]."<br/>";
echo "Bytes: ".$_POST["Bytes"];
?>
The loaded page from SecretChunkUploader.php looks like:
Password:
FileName:
PackageNumber:
Bytes:
I have tried testing isset() and it returned false for all of the post variables.
What on Earth am I doing wrong? I have tested and know that the form is fully working, it just doesn't pass the values onwards.
Thanks in advance for any help!
Instead of:
<hidden id="Bytes" name="Bytes" value="" />
Try:
<input type="hidden" id="Bytes" name="Bytes" value="" />
Same for all the others, of course.
When I submit my form, I get sent to the correct file as specified in the action attribute of my form, but the PHP in the file isn't printing the variables at all... I've combed through posts of other people having the same issue, but none of their solutions fix my problem. I've stripped my code down to a simple, textbox, button, and a php file that's supposed to print the textbox value.
If it matters, I'm running this locally in chrome, not using any servers or websites yet, I'd like to get my code working locally before I upload to my server.
HTML
<html>
<form action="Submit.php" method="post">
<input type="text" placeholder="First Name" name="firstName" id="firstName" required>
</br></br>
<input type="submit" name="submitted" value="Submit">
</form>
</html>
PHP
<html>
<body>
Name <?php echo $_POST["firstName"]; ?><br>
</body>
</html>
All I get when I click the button is a white page with "Name" printed.
Thanks!
Running scripts in response to HTTP requests is something that's done by the webserver. If you just use local files, the script will simply be loaded into the browser as a text or HTML file, it won't be executed. You can't do form processing like this.
You need to run a local server, then access the form as http://localhost/form.html
I'm new to web development and have been wrestling with this problem for several hours now, so I've decided to turn to your wisdom. I'm trying to design a little webpage with a database for my wife to store her recipes in, but I'm having trouble getting form submission to work. Here is the code for the webpage where I take the form information in:
<html><body>
Enter the information below to add a new ingredient for use in your recipes.
<form action="add_to_database.php" method="post">
Name: <input name="name" type="text" />
Serving: <input type="text" name="serving" />
Calories: <input type="text" name="calories" />
<input type="submit" />
</form>
</body></html>
And here is some silly code I've been trying to display on the page to see if I can even get the form submission to work:
<html><body>
<?php
$name = $_POST['name'];
echo $name."<br />";
?>
</body></html>
Unfortunately, the page comes back as completely back (after I hit the submit button). What's absolutely baffling to me is that I've copied and pasted the examples from this page into some files and everything seems to work fine. So it seems as though apache and php are working correctly, but I'm messing up somewhere along the way. My apologies in advance if this seems like a stupid question but for the life of me I can't figure it out.
Do you name the other file as add_to_database.php where the form is submitted. Instead you can test on teh same page by removing the add_to_database.php from the form action.
form action="" method="post">
Name: <input name="name" type="text" />
Serving: <input type="text" name="serving" />
Calories: <input type="text" name="calories" />
<input type="submit" />
</form>
and write the php code on the same page as
$name = $_POST['name'];
echo $name;
If this is not working for you. Create a php file named test.php and type phpinfo(); there.
Verify that your page is indeed being processed by PHP - obvious question, but does your PHP file have a .php extension? Do other things like phpinfo() or echo "Test"; work?
Check the error log in /var/log/apache2/error.log or similar (if on Linux, dunno where that'd be on Windows).
Try turning display_errors on in the PHP configuration (this is a good idea only for a development install, not a production server).
a bit of a longshot, but if you can verify that php is pro essing the page. Clean up your html, you are missing the dtd, head, and encoding. . hard to say how a browser is going to interpret a form (missing a name attribute) without these.
how can i pass parameters from an html page(map.html) to a php(createxml.php) without having to open the php page? Im incorporating googlemaps in html page(map.html) so i want the users to enter data on a form on the html page which will be sent to php(createxml.php) which in turn will connect to mySQL DB and create an xml format of the response the html page uses this xml output to create positions on the map since it contains longitude and latitude.
I have used the following code in the heading of the php page(createxml), but it shows the contents of php file for a brief moment redirecting me to map.html
Thanks for your time, i can post all the code if needed.
<meta http-equiv="refresh" content="0;url=http://localhost/map.html/">
It's quite simple with AJAX, using jQuery you don't have to know much about it :)
So simply import the latest jQuery Library.
Then you have your form:
<form id="my_form">
<input type="text" name="param1" />
<input type="text" name="param2" />
<input type="hidden" name="action" value="do_stuff" />
<input type="submit" value="Submit" />
</form>
and somewhere beneath that, you just paste this tiny javascript-function, which handles the submit of the form:
<script>
$('#my_form').submit(function(){
var post_params = $('#my_form').serialize();
$('#waiting').show();
$.post('the_page_you_are_on.php', post_params, function(data) {
$('#waiting').hide();
return false;
})
});
</script>
(The element (div, p...) with the id "waiting" could e.g. contain one of those fancy ajax loading images, but is not neccessary! :) If you want one to be shown, find one via google, set it as the background image of the #waiting-element and set its display to none (CSS)).
The function itself just calls the page you're on and then you've got the form variables in your post-array, so the top of your page could look something like this:
<?php
if(isset($_POST['action'])) {
switch($_POST['action']) {
case 'do_stuff' :
$param1 = $_POST['param1'];
$param2 = $_POST['param2'];
//do some DB-stuff etc.
break;
}
}
?>
I hope that helps!
It's a terrible idea, but because you don't want to use AJAX you could put the PHP in a frame and reload just that portion. Again, awful idea, but the closest you're going to get without using AJAX.
On a useful note though, AJAX is literally just one function in javascript. It's not hard at all to learn.
If you are just trying to pass parameters to a PHP page from the web browser, there are other ways to do it beyond 'Ajax'. Take a look at this page and view the source code (be sure to view the source of the included javascript file: http://hazlo.co/showlist.php?s=chrome&i=4e289d078b0f76b750000627&n=TODO
It uses an extremely basic method of changing the src of an image element, but passes information to the web server (PHP page) in the querystring of the image request. In this example I actually care about the results, which are represented as an image, but it sounds like you are just trying to pass data to the server, so you can return a 1 pixel image if you like. BTW, don't be fooled by the URL that is being used, a server rule is telling apache to process a specific PHP file when check it,GIF is requested.
You should play with it and use firebug or chrome's built in debugger to watch the requests that are being sent to the server.
You can't get any results from a PHP-script if you don't request it and process the output. If you dont't want to leave the current page, you have to use AJAX!
"but it shows the contents of php file for a brief moment" The reason is, that your browser first needs to load the entire page, then start the META-redirect. You don't need a redirect to load data from the server, but if you really want to, you should HTTP-headers for redirect.
Ok guys after hours of headache i finally found the solution! Basically i called my xmlproduce.php from inside my map.html, lemme explain so maybe will help others:
maps.html contained a googlmap API Javascript function which called my createxml.php called second.php
GDownloadUrl("second.php", function(data) )
what i did was i tweaked this call to second.php by adding some parameters in the URL like:
GDownloadUrl("second.php?strt="+ysdate+"/"+msdate+"/"+dsdate+"&end="+yedate+" /"+medate+"/"+dedate+"&id="+ide, function(data)
which is sending the parameters needed by second.php, so after that i made a small html form which called the script of googlemap api on the same file(map.html) to pass the parameters from the form to the GDownloadUrl i mentioned above, the code of the form is :
form method="get" action="">
IMEI: <input type="text" id="id" name="id" size="25" /> <br />
Start Date: <input type="text" id="ysdate" name="ysdate" size="4" value="2000" /> <input type="text" id="msdate" name="ysdate" size="1" /> <input type="text" id="dsdate" name="dsdate" size="1" /> <br/>
End Date: <input type="text" id="yedate" name="yedate" size="4" /> <input type="text" id="medate" name="ysdate" size="1" /> <input type="text" id="dedate" name="dedate" size="1" /> <br/>
<input type="button" value="submit" onClick="load()" />
</form>
afterwards i put extra constraints on the form for the values allowed.
Thanks everybody for the help, and you can always ask if somebody needs some clarification.