Pass POST data into a PHP function

Volkan

I want to upload an image file with PHP. How can I pass POST data to a PHP function in another file, which will be executed when the submit button is clicked...

here is the form:

 <!-- edit users profile picture -->
<form method="post" action="edit.php" name="user_edit_profile_picture">
    <input type="file" name="profil_slika" id="profil_slika">
    <input type="submit" name="user_edit_submit_profile_picture">

    <?php
        $con = mysqli_connect("localhost","root","","login");
        $q = mysqli_query($con,"SELECT * FROM users WHERE user_name = '".$_SESSION['user_name']."'");
        while($row = mysqli_fetch_assoc($q)){
            echo $row['user_name'];
            if($row['image'] == ""){
                echo "<img width='100' height='100' src='profile_pictures/default_user.png' alt='Default Profile Pic'>";
            } else {
                echo "<img width='100' height='100' src='profile_pictures/".$row['image']."' alt='Profile Pic'>";
            }
            echo "<br>";
        }
    ?>
</form>

and this is another PHP file with function:

elseif(isset($_POST["user_edit_submit_profile_picture"])) {
                $this->editUserPicture($_POST['profil_slika']);
            }

and function body:

public function editUserPicture($profilimage){

        $slika = $_FILES[$profilimage]['tmp_name'];
echo $slika;
        move_uploaded_file($_FILES[$profilimage]['tmp_name'],"profile_pictures/".$_FILES[$profilimage]['name']);

}

Currently I am getting this error message when I click on submit:

Notice: Undefined index: image.jpg in C:\xampp\htdocs\advanced\classes\Login.php on line 55

Thank you in advance!

user1544337

Change this:

$this->editUserPicture($_POST['profil_slika']);

To this:

$this->editUserPicture('profil_slika');

And also add enctype="multipart/form-data" to the attributes of the HTML <form>.

The reason is that profil_slika will not be passed to the $_POST array. It will be in the $_FILES array, with key profil_slika. In other words, the key you need to use for the $_FILES array is the name of the HTML input, you don't need to use $_POST at all.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pass POST data into a PHP function

From Dev

PHP POST data in header() function

From Dev

how to pass php post method string in javascript parameter function?

From Dev

How to pass data after clicking an image using PHP post?

From Dev

how to pass JSON data to php using ajax post

From Dev

Pass data to post.php in the background form fields

From Dev

How to pass data of many textbox values with POST array in PHP

From Dev

How to pass data after clicking an image using PHP post?

From Dev

Can I pass HTML form data to PHP and have PHP "post" the data?

From Dev

PHP / javascript — pass select option data/attributes to function with inline onchange

From Dev

Unable to pass the data to php function using Ajax in jquery

From Dev

PHP: Pass variable to function

From Dev

PHP Array pass to function

From Dev

How to pass data to the server using ajax and PHP? $_POST['data'] won't work

From Dev

Post function is not working in php

From Dev

Pass data to php in DropzoneJS

From Dev

Pass a PHP variable to jquery ajax post function stored in another js file

From Dev

jQuery ajax method doesn't pass post data key when using anonymous function

From Dev

How to use ajax GET or POST method to pass data to Amazon lambda node.js function

From Dev

jQuery ajax method doesn't pass post data key when using anonymous function

From Dev

Modify PHP Post Data

From Dev

post data in an array in php

From Dev

PHP parse POST data

From Dev

PHP: not able to POST data?

From Dev

Post data ajax to php

From Dev

Post data to php

From Dev

PHP Post data not sending

From Dev

How do I pass data from an AJAX PHP result to a seperate PHP function through AJAX?

From Dev

Post method cannot pass to view function

Related Related

  1. 1

    Pass POST data into a PHP function

  2. 2

    PHP POST data in header() function

  3. 3

    how to pass php post method string in javascript parameter function?

  4. 4

    How to pass data after clicking an image using PHP post?

  5. 5

    how to pass JSON data to php using ajax post

  6. 6

    Pass data to post.php in the background form fields

  7. 7

    How to pass data of many textbox values with POST array in PHP

  8. 8

    How to pass data after clicking an image using PHP post?

  9. 9

    Can I pass HTML form data to PHP and have PHP "post" the data?

  10. 10

    PHP / javascript — pass select option data/attributes to function with inline onchange

  11. 11

    Unable to pass the data to php function using Ajax in jquery

  12. 12

    PHP: Pass variable to function

  13. 13

    PHP Array pass to function

  14. 14

    How to pass data to the server using ajax and PHP? $_POST['data'] won't work

  15. 15

    Post function is not working in php

  16. 16

    Pass data to php in DropzoneJS

  17. 17

    Pass a PHP variable to jquery ajax post function stored in another js file

  18. 18

    jQuery ajax method doesn't pass post data key when using anonymous function

  19. 19

    How to use ajax GET or POST method to pass data to Amazon lambda node.js function

  20. 20

    jQuery ajax method doesn't pass post data key when using anonymous function

  21. 21

    Modify PHP Post Data

  22. 22

    post data in an array in php

  23. 23

    PHP parse POST data

  24. 24

    PHP: not able to POST data?

  25. 25

    Post data ajax to php

  26. 26

    Post data to php

  27. 27

    PHP Post data not sending

  28. 28

    How do I pass data from an AJAX PHP result to a seperate PHP function through AJAX?

  29. 29

    Post method cannot pass to view function

HotTag

Archive