<?php
SESSION_start();

              if(!isset($_SESSION['email']))
                {

                echo"access denied";
                exit;
                }
                else{
                $email=$_SESSION['email'];
               include("menu.php");
                $num=$_SESSION['num'];
                $date=date("Y/m/d");

                }


?>



<html>
           <head>
           </head>


            <body>
             <div style="position:absolute; top:143px; left:292px; width:999px; height:244px; background-color:pink; border-radius:15px;">
             <table>
            <form  enctype="multipart/form-data"  action=""  method= "POST">

            <tr><td>Document Type:</td><td><select name="doc_type" >
                     <option value="police report" selected="true">Police report file</option>
                     <option value="medical report">Medical report file</option>
                     <option value="purchase bills">Purchase invoice report</option>
                     <option value="survey report">Survey report file</option>
            </select></td></tr>
              <tr><td>Settlement Number:</td><td><input type="text" name="cnum" value="<?php echo $num;?>"  readonly /><br /></td></tr>
              <tr><td>Created Date :</td><td><input type="text" name="doc_cdate" value=""  /></td></tr>
              <tr><td>Created By :</td><td><input type="text" name="doc_cby"  value=" <?php echo $email; ?> " /></td></tr>
              <tr><td>Description :</td><td><input type="text" name="doc_comment"  value=" " /></td></tr>
              <input type="hidden" name="max_file_size" value="124111111"/>
                <tr><td>Pick your document ?</td><td><input type="file" size="2022222" name="thefile" /></td></tr>
               <tr><td></td><td><input type="submit" name="submit" value=" Uplaod this!"></input></td></tr>


                </form>
  </div>
             </body>
              </html>
<?php


mysql_connect("localhost","root","");
mysql_select_db("shri");    

    $sql="select * from doc where cnum='$num'";
    $result=mysql_query($sql);
    $count=mysql_affected_rows();

    if($count>0)
    {

         echo"<table style=\"  border: 1px solid black; background-color:pink; width:999px; cellborder:1; position:relative; top:53px;border-radius:22px; \">";
        echo"<tr><td><h3>Document View</h3></td></tr>";
    echo"<tr><td style=\"  border: 1px solid black;\">Settlement No</td><td style=\"  border: 1px solid black;\">Document Type</td><td style=\"  border: 1px solid black;\">Created date</td><td style=\"  border: 1px solid black;\">Created by</td><td style=\"  border: 1px solid black;\">Comment</td><td style=\"  border: 1px solid black;\">Veiw</td></tr>";
      while($row=mysql_fetch_array($result))
                { $cnum=$row['cnum'];
                  $doc_type=$row['doc_type'];
                  $doc_cdate=$row['doc_cdate'];
                  $doc_cby=$row['doc_cby'];
                  $path=$row['path'];
                  $doc_comment=$row['doc_comment'];

        echo"<tr><td style=\"  border: 1px solid black;\">$cnum</td><td style=\"  border: 1px solid black;\">$doc_type</td><td style=\"  border: 1px solid black;\">$doc_cdate</td><td style=\"  border: 1px solid black;\">$doc_cby</td><td style=\"  border: 1px solid black;\">$doc_comment</td><td style=\"border: 1px solid black;\" ><a href=\"$path\" style=\"color:red;\">Click here</a></td></tr> ";
        }echo"</div>";
        echo"</table>";


    }
    else
    {echo"<table style=\" border:1 solid gray ; background-color:pink ; width:999px; cellborder:1; position:relative; top:63px; \">";
      echo"<tr><td>Settlement No</td><td>Document Type</td><td>Created date</td><td>Created by</td><td>View</td></tr>";
         echo"<tr><td colspan=\"5\"><center/>No rows returned</td></tr>";
         echo"</div>";
         echo"</table>";


    }








      if((isset($_POST['submit'])))
        {    
             $path="";
                 $doc_type=$_POST['doc_type'];
                $doc_cby=$_POST['doc_cby'];
                $doc_cdate=$_POST['doc_cdate'];
                $cnum=$_POST['cnum'];
                $doc_comment=$_POST['doc_comment'];
       if(!empty($doc_comment))
        {
            if(($_FILES['thefile']['size']==0)|| (empty($_FILES['thefile']['tmp_name'])))
               {
                echo("<p>You didn't select document </p>\r\n");
               } else if($_FILES['thefile']['size'] > 50001110) 
                        {
                          echo("<p>The file was too large.</p>\r\n");
                       } else if($_FILES['thefile']['error'] !== UPLOAD_ERR_OK) 
                                { 


                                echo("<p>There was an error uploading.</p>\r\n");
                                        } 
     else {
        if(!file_exists('/image_uploaded')) mkdir('image_uploaded');


                 if(move_uploaded_file($_FILES['thefile']['tmp_name'],'image_uploaded/'. $_FILES['thefile']['name'])) 
                  { echo("<p>File uploaded successfully!</p>\r\n");
                  $path='image_uploaded/'.$_FILES['thefile']['name'];

                mysql_connect("localhost","root","");

                mysql_select_db("shri");
                $sql=("insert into doc(doc_type,cnum,doc_cdate,doc_cby,path,doc_comment) values('$doc_type','$cnum','$doc_cdate','$doc_cby','$path','$doc_comment')");
                $result=mysql_query($sql);  
                $count= mysql_affected_rows();
                echo $count;
               if(mysql_affected_rows() > 0)
                            {  
                             echo "Your document has been uploaded !!";
                               exit;
                             }                                                                 
                 else{  
                      echo "Oye!we missed it ,please submitagain,Thank you"; 
                       exit;
                      }



                  }else {
                          echo("<p>There was an error moving the file.</p>\r\n");
                         }
         }


            } 

}




?>

Recommended Answers

All 3 Replies

Sorry i missed following para...

above code works fine with following functionality.

record gets inserted to doc table with correct url(selected by the user while uploading]. However i am facing following problem. whenever i click on refresh button after adding records to doc table, same records gets inserted again. in other words as and when refresh button is clicked , last inserted records gets inserted again and again.....please let me know what went wrong ... I am validating whether user is clicked submit button or not before inserting record. however it fails.. please help me . thanks ina dvance

That is normal browser behavior
Redirect to a deferent page when your done:

     if(mysql_affected_rows() > 0)
        {
        header("location : thankyou.html");
        exit;
        }

Thank you very much!! it is working fine now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.