从表单处理图像(图像不用作提交按钮)

I am trying to put an image link into a form (not as a submit button). I am having trouble extracting the image when I process the form.

Here is my php code for putting the image in a form...

$picture = "
    <div id='photo'>
        <input type='image' name='image' src='www.sampleimage.jpg'>
    </div>";

<div class='formData'>
    <form action='recToDb.php' method='post'>" . 
        $picture . 
        "<input type='submit' name='toDB'>
    </form>
</div>";

The image is uploaded as HTML and that part works fine. Once the user is satisfied, they can hit the submit button. At that point, I want to add the image (or the source of the image) to a database. For now, I am just trying to extract the image with this code...

if (isset($_POST['toDB']))
   {echo $_POST["image"];}

If I do var_dump($_POST), the image is not even in the array so I believe that the image is not going into the form, but I don't know exactly what my problem is.

Note that there are other things in the form that I did not display in the above code that I have no problem extracting.

 $picture = "
<div id='photo'>
    <input type='image' name='image' src='www.sampleimage.jpg'>
</div>";

$picture should not pull the HTML, rather it should just contain the uploaded content.

$picture = $_POST["image"];

then you should be able to call $picture. As to my understanding, you are trying for:

  • After the image is uploaded, the image is displayed under the upload form.
  • The picture is uploaded to the server.
  • An entry is made in the database with the URL of the picture.

EDIT: I feel I am not getting what you are trying to accomplish. Could you please link me to your whole code?
Are other values being inserted into the database? If you are trying to accomplish just the image upload I suggest added another input.

To display all errors that are not automatically thrown at you please add

error_reporting(E_ALL);
ini_set('display_errors', '1');

after the code.