Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create form to update file using PHP?
    primarykey
    data
    text
    <p>I have written a PHP script which allows me to modify and update a file on a webpage, which works, but the script right now presents the entire contents of the file in a text area. I would like to extract just the string from the file and pre-populate it in a form text field (instead of a text area). </p> <p>Below are the two files I need to update. I would like to just update the IP addresses. So the form would ideally show that mail.helloworld.com current maps to "208.164.222.2" and populate that IP address in a form text field. Same idea for the /etc/postfix/main.cf file as shown below.</p> <p>/etc/hosts</p> <p>IPAddress Hostname Alias 127.0.0.1 localhost deep.openna.com 208.164.222.2 mail.helloworld.com mail 208.164.222.3 web.helloworld.com web</p> <p>/etc/postfix/main.cf</p> <p>relayhost= 192.168.1.10</p> <p>===</p> <p>Current working script using textarea:</p> <pre><code>&lt;form action="&lt;?php echo $PHP_SELF;?&gt;" method="post"&gt; &lt;textarea rows="13" cols="110" name="content"&gt; &lt;? $fn = "/etc/postfix/main.cf"; print htmlspecialchars(implode("",file($fn))); ?&gt; &lt;/textarea&gt;&lt;/br&gt; &lt;input id= "relayhost_button" type="submit" value="Update"&gt; &lt;/form&gt; &lt;? $fn = "/etc/postfix/main.cf"; $content = stripslashes($_POST['content']); $fp = fopen($fn,"w") or die ("Error opening file in write mode!"); fputs($fp,$content); fclose($fp) or die ("Error closing file!"); echo "&lt;meta http-equiv=\"refresh\" content=\"0; url=done.php\" /&gt;\n"; ?&gt; </code></pre> <p>Here is the current textarea based form:</p> <p><img src="https://i.stack.imgur.com/pHdEM.png" alt="enter image description here"></p> <p>New text field based form I want:</p> <p><img src="https://i.stack.imgur.com/W07dL.png" alt="enter image description here"> As always, thanks folks!</p>
    singulars
    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.
    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