Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am trying to use file upload in while loop but i can upload a file for the first record of the list, i cannot upload for other records. whenever i trying to upload for a second record or any other record of the list its showing me please select a file alert which i have put for blank file.it allow me upload for the first record only. how can i solve it?

thanks in advance.

below files i have used.

<?php
$select="select * from tbl_post_artical where writername='".$_SESSION["writer_id"]."' order by id desc;";
$query=mysql_query($select) or die($select);

    while($row=mysql_fetch_array($query))
    {  
    ?>

    <td align="center" >
    <?php if($row['action']!='approved')
    {
    echo '<input type="file" name="fileToUpload" id="fileToUpload" value='.$row['id'].' />
    <img src="images/fileupload.png"  onclick="savepic('.$row['id'].')" title="UPLOAD"/>';
    } 
    else
    {
    echo $str='<font color="green">DONE</font>';
    } ?>
    <?php } ?>


**doajaxfileupload.php**


<?php
session_start();
if($_SESSION["writer"]=='') print('<script>window.location.href="login.php"</script>');
include('conn.php');
include('function/fun.php');

$id=$_REQUEST['id'];

    $ImageName = $_FILES['fileToUpload'][name];
    $fileElementName = 'fileToUpload';

    if(empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none')
    {
        echo '<script>alert("Select File")</script>';
    }
    else 
    {
        $path = 'file/'; 
        $location = $path . $_FILES['fileToUpload']['name']; 
        move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $location); 

         $s="update tbl_post_artical set
                file_name='$ImageName',
                upload_date='".date('m/d/y')."'
                where id='".$id."' and writername='".$_SESSION["writer_id"]."'";
        $result=mysql_query($s) or die($s);
                echo '<script>alert("File Uploaded Successfully")</script>';
            die("<script>window.location.href='writer_my_job.php'</script>");
    }       


?>
share|improve this question
1  
Wow, how do people maintain code like that? – elclanrs 36 mins ago
Can you show only the relevant code ? PHP code has probably nothing to do here – Antoine 33 mins ago
ok i'll show file upload code – user2396388 31 mins ago
now u can see thats my file upload code – user2396388 30 mins ago
1  
Is that code running on production server? Have you heard about SQL injection vulnerabilities? Your "id" request parameter gets inserted verbaim into SQL statement. What means I can pass any SQL statements (e.g. DELETE FROM update tbl_post_artical set) right from URL – Maksym Kozlenko 23 mins ago
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.