Uploading image using php results in accept-file.php was not found - php

Hi im trying to upload an image to a database using php but every time i press the submit button i get the error
accept-file.php was not found
i dont see anywhere in my code where it will be directing to that is there something im missing?
<?php
session_start();
$link = mysqli_connect("localhost","root","","pictureupload");
if(isset($_POST['submit'])){
$imagename=$_FILES["iamge"]["name"];
$imagetmp=addslashes (file_get_contents($_FILES['image']['tmp_name']));
$insert_image="INSERT INTO images VALUES('$imagetmp','$imagename')";
mysqli_query($link,$insert_image);
}
?>
<!DOCTYPE html>
<html>
<head>
<Title>HomePage</Title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form action="accept-file.php" method="post" enctype="multipart/form-data">
Your Image: <input type="file" name="image" size="25" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

change your form tag to
<form action="?"

Your form has "accept-file.php" set as action:
<form action="accept-file.php" method="post" enctype="multipart/form-data">
This is where the form data will be sent to via the set method (POST in this case) and using the given encoding type.
After you click on "submit" your browser will call this script, which in your case does not exist. Therefore your webserver will return the error message instead of handling the upload.
To make it work you need to change the action to the filename of your script, which you have posted above.

Related

Echo textarea's value with PHP

I want to echo the textarea value with PHP, so I create a simple form with HTML, and inside it I include textarea element with name of b64_place and then input to submit the values.
I check if b64_place is set, and if it is I echo the value of the textarea. But my program doesn't even get into the condition block, I try debugging and it is just not doing nothing.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<form action="index.php" method="GET">
<textarea name="b64_place" form="encode">Enter text here:</textarea>
<input type="submit" value="Encode">
</form>
<?php
if (isset($_GET['b64_place'])) {
$base64e_text = htmlspecialchars($_GET['b64_place']);
echo $base64e_text;
}
?>
</body>
</html>
Your textarea contains an attribute form This attribute is used to define the id of the form this input is attached to. So, when you submit the form, the textarea isn't bound with that form and the datas aren't send
You can either add an id to the form :
<!-- check this ----------------------v---------v -->
<form action="index.php" method="GET" id="encode">
<textarea name="b64_place" form="encode">Enter text here:</textarea>
<input type="submit" value="Encode">
</form>
or simply remove the form="encode"
Edit based on suggestion from senior SO members,
The reason i recommend you to change the method to POST is because of the length limit of the GET method. At some point you may want to encode very large data and it may get trimmed of because of URL length limit. But with POST you don't have to worry about this restriction.
Steps to solve your issue.
If your Form and your PHP code is in the same file changethe action="index.php" to action="" and change the method="GET" to method="POST"
In text area use placeholder to tell the user what to input instead of writing it between the tags.
change $_GET to $_POST everywhere in your code.
You can copy the following code into the index.php and it will work fine.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<form action="" method="POST">
<textarea name="b64_place" placeholder="Enter text here:"></textarea>
<input type="submit" value="Encode">
</form>
<?php
if (isset($_POST['b64_place'])) {
$base64e_text = htmlspecialchars($_POST['b64_place']);
echo $base64e_text;
}
?>
</body>
</html>

Getting post data from form with iframe doesn't work PHP

I have this code:
<!DOCTYPE html>
<html>
<body>
<iframe name="votar" style="display:none;"></iframe>
<form id="excel form" method="post" target="votar">
<input type="submit" name="test" id="test" value="RUN" /><br/>
</form>
</body>
</html>
<?php
if(isset($_POST['test']))
{
echo "hello world";
}
?>
what am I trying to do? well I try to get hte post data from this form without reloading the page and without using ajax, but what am I doing wrong? I tried looking around, but all the other solutions are to long or just not prectical for my website. please help.
EDIT
just changed submit to test, doesn't matter.
<form action="" method="post" >
<!-- code -->
</form>

HTML form for file upload won't return file name

I have a simple HTML file with a form to upload a file and PHP code to process the uploaded file. I've tried a bunch of input types and they all work except for input type="file". Nothing gets displayed. The code is attached.
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data"> Select image to upload:
<input type="file" name="test.f" id="test.f">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
The processing php code is:
<?php
echo "Hello world";
echo $_FILES["test.f"];
?>
you should call the file by name if it does not work please change the file name in your form
name="test"
$_FILES["test"]['name'];

Linking html to php with $_POST

I have been trying to create a form that reads a post from an HTML form and displays an element from that post IF it detects that the post exists.
However, each time the post is submitted, it simply reloads the form as though no post were provided.
<!DOCTYPE html>
<html>
<head>
<title>Upload from Manifest</title>
</head>
<body>
<?php
if (isset($_POST['manifest'])) {
echo 'we are in the IF';
echo($_POST['manifest']);
}
?>
<h1>Submission from manifest into main db</h1>
<div class="container offset-top120">
<form method="post" action="https://nhsggc.cogiva.com/prism/loadFromManifest.php" enctype="multipart/form-data">
<input id="manifest" type="text" />
<input id="submit" value="Submit" type = "submit" />
</form>
</div>
</body>
</html>
Your form is going to either a different page (https://nhsggc.cogiva.com/prism/loadFromManifest.php so check for that first) if you wanted it to go to same page, you can give the action as just '#', or put in the whole URL like you have.
You're missing the name attribute from your submit input and text input. Read up on the name attribute!
<input id="manifest" type="text" name="manifest">
<input id="submit" value="Submit" type="submit" name='submit' />
Then your PHP should look like this:
<?php
if (isset($_POST['submit'])) {
echo 'Inside an if';
echo $_POST['manifest'];
}
Then it should work.

onclick input type submit

In a form I have an <iframe> that contains a PHP file (editor.php). This PHP file contains an HTML form.
Well, when I do a "submit form", I call the same PHP file, for example main.php.
When I press the submit button, I have "onclick method" that it calls a Javascript function inside editor.php. This function executes the form.
My problem is that main form is executed correctly but the second form is not.
In the second loop of the form of editor.php receives nothing.
**Check this way it will work as you expected**
//main.php
<html>
<head>
<script type="text/javascript">
function validateMain()
{
alert('main');
}
function validateSub()
{
alert('sub');
}
</script>
</head>
<body>
<form id="main" onsubmit="return validateMain();">
<input type="text" name="first" id="first"/>
<input type="submit" value="Submit Main"/>
</form>
<iframe name="ifr-form" id="ifr-form" src="test.html"></iframe>
</body>
</html>
//test.html the second form included through iframe
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<form id="sub" onclick="return window.top.validateSub();">
<input type="text" name="first" id="second"/>
<input type="button" value="Submit Sub" />
</form>
</div>
</body>
</html>
you must check if php and iframe are compatible, as far as i Know I don't think that frames and php gives any output, hope this helps.

Categories