Jump to content

Inserting Data in MySQL Database with $_FILE Error


liamk

Recommended Posts

<?php
    ob_start();
    
    if(isset($_POST['add'])) {
    
    $target = "admin/stockin/files/"; 
    $target = $target . basename( isset($_FILES['file']['name'])); 
    
    $brands= $_POST['brands'];
    $season= $_POST['season'];
    $file= isset($_FILES['file']['name']);
    $branch = $_POST['branch'];
    $auth = $_POST['auth'];
    $date = $_POST['date'];
    $status = $_POST['status'];

    
    $query = mysql_query("INSERT INTO stockin (brands, season, `file`, branch, auth, date, status) VALUES('$brands','$season','$file','$branch','$auth','$date','$status')") or die(mysql_error);
    
     if(move_uploaded_file(isset($_FILES['file']['tmp_name'], $target))) 
     { 
     
     //Tells you if its all ok 
     echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
     } 
     else { 
     
     //Gives and error if its not 
     echo "Sorry, there was a problem uploading your file."; 
     } 
    
    //echo "<meta http-equiv='refresh' content='0;url=page.php?id=stockin' />";
    }
    else
    {
    ?>
        
        <fieldset>
        <legend>Post Request</legend>
        <form method='POST'>
        <label>Brand:</label> 
        
        <?php
        
        $sql = "SELECT brands FROM brands ORDER BY brands";
        $result = mysql_query($sql);
        
        echo "<select name='brands'>";
        while ($row = mysql_fetch_array($result)) {
            echo "<option value='" . $row['brands'] . "'>" . $row['brands'] . "</option>";
        }
        echo "</select>";
        
        ?>
        <br />
        <label>Season:</label> 
        
        <?php
        
        $sql = "SELECT season FROM season";
        $result = mysql_query($sql);
        
        echo "<select name='season'>";
        while ($row = mysql_fetch_array($result)) {
            echo "<option value='" . $row['season'] . "'>" . $row['season'] . "</option>";
        }
        echo "</select>";
        
        ?>
        <br />
        <label>File:</label> <input type='file' size='35' maxlength='255' name='file' /><br />
        <label>Branch:</label> 
        
        <?php
        
        $sql = "SELECT branch FROM branch";
        $result = mysql_query($sql);
        
        echo "<select name='branch'>";
        while ($row = mysql_fetch_array($result)) {
            echo "<option value='" . $row['branch'] . "'>" . $row['branch'] . "</option>";
        }
        echo "</select>";
        
        ?>
        <br />
        
        <?php
            $query = "SELECT * FROM users WHERE username='$usr'"; 
            	 
            $result = mysql_query($query) or die(mysql_error());
            
            while($row = mysql_fetch_array($result))
                {
            
                echo "<label>Authorized By:</label> <input readonly='readonly' type='text' size='35' maxlength='25' name='auth' value='" . $row['name'] . "' /><br />";
            }   
        ?>
        <label>Date:</label> <input readonly="readonly"type='text' name='date' size='35' value='<?php echo date("D M d, Y G:i a"); ?>' /><br />
        <label>Status:</label> 
        
        <select name='status'>
        <option value='pending'>Pending</option>
        <option value='ready'>Ready</option>
        <option value='outofstock'>Out of Stock</option>
        </select>
        <br />
        
        <input name='add' type='submit' value='Post Request' />
        </form>
        </fieldset>
    <?
    }
    ?>

 

There is the code and i dont understand why it wont upload. It returns with the error message cant upload file or whatever it says.

 

Help would greatly appreciated :)

 

Liam.

Right. You're only passing the value returned from isset($_FILES['file']['tmp_name'], $target) to move_uploaded_file(), which will be a boolean TRUE/FALSE value. You're using isset() in the wrong manner, and have too many things enclosed in its parentheses, too.

 

if(move_uploaded_file(isset($_FILES['file']['tmp_name'], $target)))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.