brietsparks
brietsparks

Reputation: 5016

submit form does not pass data to PHP

The submit form does not seem to pass along the uploaded file. The code is supposed to display "array" when a file is uploaded. Nothing happens when submit is pressed

<?php
    $conn = mysql_connect("localhost","root","") or die(mysql_error());

    mysql_select_db ('coop',$conn);

    if(isset($_POST['submit']))
    {
        $file = $_FILES['file']['tmp_name'];

        $handle = fopen($file,"r");

        while(($fileop = fgetcsv($handle,1000,"|")) !== false)
        {
            echo $fileop;
        }
    }


?>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Untitled</title>

</head>
<body>
        <form method="post" action="index.php" enctype="multipart/form-data">
            <input type="file" name="file" />
        </form>
        <br />
        <input type="submit" name="submit" value="submit">
</body>
</html>

Upvotes: 0

Views: 90

Answers (2)

Patrick
Patrick

Reputation: 3367

Your submit is outside of the form tags, Fix your HTML and the posting should work.

Upvotes: 1

Arian Faurtosh
Arian Faurtosh

Reputation: 18511

Your <form> </form> tag should wrap all elements of the form. Like the following:

<form method="post" action="index.php" enctype="multipart/form-data">
    <input type="file" name="file" />
    <br />
    <input type="submit" name="submit" value="submit">
</form>

Upvotes: 3

Related Questions