<div>Hi Jamie Holly</div>
<div>Thanks for kind reply.</div>
<div> </div>
<div>You are right, I just deleted the entry and added a new entry in files table, it looks fine.</div>
<div> </div>
<div>I have a small concern. The &#39;fid&#39; column in files is of type serial. But I do not want <font size="3" face="Times New Roman">unnecessary</font>  increment of fid values. For that purpose, while inserting new record, I am just making use of last fid value of that user. Code as below</div>

<div> </div>
<div><font>
<p>db_query(&quot;INSERT INTO {files} (fid, uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, %d, &#39;%s&#39;, &#39;%s&#39;, &#39;%s&#39;, %d, %d, %d)&quot;, $LastFID, $file-&gt;uid, $file-&gt;filename, $file-&gt;filepath, $file-&gt;filemime, $file-&gt;filesize, $file-&gt;status, $file-&gt;timestamp);</p>

<p>Hope I am not doing any mistake while re-using last FID value.</p>
<p> </p>
<p>Regards</p>
<p>Kamal</p>
<p>NECS, Bangalore</p></font></div>
<div><br><br> </div>
<div class="gmail_quote">On Sun, Aug 26, 2012 at 8:09 PM, Jamie Holly <span dir="ltr">&lt;<a href="mailto:hovercrafter@earthlink.net" target="_blank">hovercrafter@earthlink.net</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class="gmail_quote">
<div text="#000000" bgcolor="#FFFFFF">
<div>You aren&#39;t deleting the record from the database, just the file from the file system. You should add in there a:<br><br>db_query(&#39;DELETE FROM {files} WHERE fid = %d&#39;, $FID);<br><br>Also do that on any other linked tables you have added in.<span><font color="#888888"><br>
<pre cols="72">Jamie Holly
<a href="http://www.intoxination.net/" target="_blank">http://www.intoxination.net</a> 
<a href="http://www.hollyit.net/" target="_blank">http://www.hollyit.net</a></pre></font></span>
<div>
<div>On 8/26/2012 10:25 AM, Kamal Palei wrote:<br></div></div></div>
<div>
<div>
<blockquote type="cite">
<div>Hi All</div>
<div>I am using Drupal 6.26.</div>
<div> </div>
<div>I am trying to upload a file. One user can upload only one file.</div>
<div>After a while, if user wants to upload another file, I need to delete the first file and upload the second file.</div>
<div>To delete the first file, I do a query to get the first file name, deletes first file and uploads the second file.</div>
<div>After a while, if user wants to upload another file, when I do query to get the second file name (as I want to delete the second file now), I always get the first file name.</div>
<div>So I am not able to delete the second file.</div>
<div> </div>
<div>Probably database cache plays a role here, how can I make sure, my query returns the latest data present in table, query should not pick the data from cache.</div>
<div> </div>
<div>Please refer code below.</div>
<div> </div>
<div> global $user;<br> $FID = -1;<br> <br> $result = db_query(&quot;SELECT fid, filepath FROM {resubmt_table} LEFT JOIN {files} USING (fid) WHERE resubmt_table.uid = %d&quot;, $user-&gt;uid);<br> $obj = db_fetch_object($result);<br>
 if($obj)<br> {<br>  $FID = $obj-&gt;fid;<br>  if($obj-&gt;filepath)<br>  {<br>   if(file_exists($obj-&gt;filepath))<br>   {<br>    drupal_set_message(&quot;File exists deleting &quot; . $obj-&gt;filepath);<br>    unlink($obj-&gt;filepath);<br>
   }<br>   else<br>   {<br>    drupal_set_message(&quot;File does not exists, so not able to delete, file = &quot; . $obj-&gt;filepath);<br>   }<br>  }<br> }</div>
<div><br> </div>
<div>Many times, I am not able to delete the file.</div>
<div>Please suggest how can I fix this issue.</div>
<div> </div>
<div>Thanks</div>
<div>Kamal</div>
<div>NECS, Bangalore</div>
<div> </div>
<div> </div>
<div> </div><br>
<fieldset></fieldset> <br></blockquote><br></div></div></div><br>--<br>[ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br></blockquote></div><br>