"fwrite" problem

Discussion in 'PHP' started by ItamarP, Aug 28, 2009.

  1. #1
    I want to write data into an already exsiting code:


    Delete:

    <form method="post" action="this file's name">
    <select name='delete'>
    I want to write the data here
    </select>
    <input type="submit" value="submit">

    I want to write the data in the "select" form (the bold section), not in the beggining of the file,


    how can i do it ?


    thanks in advance
     
    Last edited: Aug 28, 2009
    ItamarP, Aug 28, 2009 IP
  2. nomatteus

    nomatteus Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You're going to need some sort of template functionality.

    In your form (say deleteform.html) have:
    <form method="post" action="this file's name">
    <select name='delete'>
    ##DATA##
    </select>
    <input type="submit" value="submit">
    Code (markup):
    Notice the ##DATA## part--this is a 'variable' where you want your data to go.

    Basically you need to get the file contents into a string (try file_get_contents()), then run a find and replace (like str_replace()) finding '##DATA##' and replacing with your data.

    Then in your new variable you'll now have the data you need. Now you just need to overwrite the current contents of deleteform.html with the new HTML created, and that should be it!

    There are other ways to do this, but this should at least give you a starting point of what you need to do.
     
    nomatteus, Aug 28, 2009 IP
  3. ItamarP

    ItamarP Member

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    any other suggestions?
     
    ItamarP, Aug 29, 2009 IP
  4. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    You can overwrite

    
    <?php 
    if (isset($_POST["Submit"])) { 
    
    $string = '<?php  
    $dbhost = "'. $_POST["dbhost"]. '"; 
    $dbuname = "'. $_POST["dbuname"]. '"; 
    $dbpass = "'. $_POST["dbpass"]. '"; 
    $dbname = "'. $_POST["dbname"]. '"; 
    $prefix = "'. $_POST["prefix"]. '"; 
    $user_prefix = "'. $_POST["user_prefix"]. '"; 
    $dbtype = "'. $_POST["dbtype"]. '"; 
    ?>'; 
    
    $fp = fopen("config.php", "w"); 
    fwrite($fp, $string); 
    fclose($fp); 
    } 
    include "config.php"; 
    ?>
    
    <form action="submit.php" method="post" name="install" id="install"> 
      <p><?=$dbhost?> <input name="dbhost" type="text" id="dbhost" value="<?=$dbhost?>"> DB Host</p> 
      <p><?=$dbuname?> <input name="dbuname" type="text" id="dbuname" value="<?=$dbuname?>"> DB Username</p> 
      <p><?=$dbpass?> <input name="dbpass" type="password" id="dbpass" value="<?=$dbpass?>"> DB Pass </p> 
      <p><?=$dbname?> <input name="dbname" type="text" id="dbname" value="<?=$dbname?>"> DB Name </p> 
      <p><?=$prefix?> <input name="prefix" type="text" id="prefix" value="<?=$prefix?>"> DB Prefix</p> 
      <p><?=$user_prefix?> <input name="user_prefix" type="text" id="user_prefix" value="<?=$user_prefix?>"> Userprefix</p> 
      <p><?=$dbtype?> <input name="dbtype" type="text" id="dbtype" value="<?=$dbtype?>"> DB Type </p> 
      <p><input type="submit" name="Submit" value="Install"></p> 
    </form>
    
    
    PHP:
     
    baris22, Aug 29, 2009 IP
  5. picos

    picos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #5
    it not work in IE,
    replace : <p><input type="submit" name="Submit" value="Install"></p>
    by : <input type="hidden" name="Submit" value="122345">
    <input type="submit" value="Install">
     
    picos, Sep 1, 2009 IP