Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to prevent php fwrite() from overwriting a line of text on file?
    primarykey
    data
    text
    <p>I have extracted following lines of code from my script.</p> <pre><code> $i=0; $j=0; $fp=fopen('C:\xampp\htdocs\Lib_auto_project\Deleted_Records\delete_log.sql','a+');// File where the string is to be written foreach($_POST as $temp)//repeat for all the values passed from the form { if($j==0) { $result_set=$mysqli-&gt;query("select * from {$_SESSION['table_name_1']} where Copyid=$temp"); $result_set=$result_set-&gt;fetch_array(MYSQL_BOTH); ++$j; } if($temp!='Drop')// Drop is simply the value of submit buttom { $date=mysql_query("select now() as current_date_time") or die(mysql_error()); $date=mysql_fetch_array($date,MYSQL_BOTH); $result="\n"."INSERT INTO delete_book_log // this is the string begining with line break and followed by sql insert statement VALUES( '{$result_set["Bid"]}', '$temp', '{$result_set["Name"]}', '{$result_set["Publication"]}', '{$result_set["ISBN"]}', '{$result_set["Author"]}', '{$result_set["Edition"]}', 'in', '{$result_set["Book_Baseid"]}', '{$date['current_date_time']}' );"; fflush($fp); fwrite($fp,$result); $mysqli-&gt;query("Delete from {$_SESSION['table_name_1']} where copyid=$temp"); $i++; } } fclose($fp); </code></pre> <p>![screen shot]: <a href="http://i.stack.imgur.com/dOzSj.jpg" rel="nofollow">http://i.stack.imgur.com/dOzSj.jpg</a></p> <p>As you can see from the screen-shot, when one or more of the records are selected and the drop button is clicked, I want the records to be deleted from the database but want the corresponding sql insert statements to be written into a <code>file(C:\xampp\htdocs\Lib_auto_project\Deleted_Records\delete_log.sql)</code>.For that to happen I have written the above piece of code. Now the problem is when I select the records and drop them all goes as desired. When I do the same any other instant I want similar sql insert strings, stored as shown above in $result, appended to the end of the <code>file(C:\xampp\htdocs\Lib_auto_project\Deleted_Records\delete_log.sql)</code>. This does not quite happen. Rather the previously written strings get overwritten by the new one. I have tried it over and over but only the recent strings get overwrite the old ones. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload