evAN-_^ Posted May 8, 2008 Share Posted May 8, 2008 Okay here I go, I'm terrible with PHP so bare with me. What I'm wanting to do is create a small, very basic file editing system, now here's my problem. I have the following files; Contents of, form.php <form action="processscript.php" method="post"> <textarea rows="25" cols="40" name="content"> <? $fn = "test.txt"; print htmlspecialchars(implode("",file($fn))); ?> </textarea> <input type="submit" value="Change!"> </form> Contents of, processscript.php <? $fn = "test.txt"; $content = stripslashes($_POST['content']); $fp = fopen($fn,"w") or die ("There was an error in opening the modified file."); fputs($fp,$content); fclose($fp) or die ("There was an error in closing the modified file."); echo "You've successfully updated $fn, you'll be redirected in 3 seconds..."; ?> <meta HTTP-EQUIV="REFRESH" content="3; url=test.txt"> Now, obviously those two files together update the 'test.txt' file, right? Well, Above the text box in 'form.php' I want to add a jump down menu, which is easy done in Dreamweaver - like so; Now, what I want to do (which I cannot figure out how to do...) is that when you click one of the values on the jump down menu, for example we'll say Option 2, I'd like the value of $fn (which is test.txt) to change to another file, basically I want to be able to use this drop down file to edit multiple pages. I hope I've explained this clearly, I really need some help, cheers! Link to comment https://forums.phpfreaks.com/topic/104742-change-value-in-php-code/ Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 you'll need to add javascript code to your dropdown navigating to your PHP scripts. use the onchange() event to navigate to a PHP page, either a separate page for each option or 1 page that handles each option via different GET parameters passed on the onchange() event. Link to comment https://forums.phpfreaks.com/topic/104742-change-value-in-php-code/#findComment-536170 Share on other sites More sharing options...
FVxSF Posted May 8, 2008 Share Posted May 8, 2008 From what I under stand, you want that drop down list to contain the other files that you'd like to edit? What you'll need to do is write a script that lists the files of a given directory. Something like: <?php $Location = "."; $OptionsList = ""; if( $Handle = opendir($Location) ) { while( ($FFName = readdir($Handle)) !== false ) { $OptionsList .= "<option value='$FFName'>$FFName</option>"; } } closedir($Handle); ?> For this script, you'll probably want to save your text files in their own folder. $Location = "./textfiles"; This creates the Option List in the Select Form. To show the list is easy: <select name="myfiles"> <?=$OptionsList; ?> </scelect> You'll need a javascript code that will automatically submit once you select your file. I'm not 100% sure of the function as I don't do javascript too often. Also I'd add this dropdown in it's own form so that once the submit command is passed you don't save any unwanted changes to the text document. Just replace the $fn with "./textfiles/". $_POST[myFiles] (or however you'd like to set it up) Link to comment https://forums.phpfreaks.com/topic/104742-change-value-in-php-code/#findComment-536181 Share on other sites More sharing options...
evAN-_^ Posted May 8, 2008 Author Share Posted May 8, 2008 I really appreciate the help, but I'm really confused lol... as I said, I got no idea =S Link to comment https://forums.phpfreaks.com/topic/104742-change-value-in-php-code/#findComment-536192 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 if our advice doesn't make any sense to you, you may want to look up some tutorials on Javascript and PHP. if you plan on continuing to learn PHP, i suggest dropping Dreamweaver and using a text or code editor. i use BBEdit. Link to comment https://forums.phpfreaks.com/topic/104742-change-value-in-php-code/#findComment-536200 Share on other sites More sharing options...
marklarah Posted May 8, 2008 Share Posted May 8, 2008 Agreed. There are three types of website makers; - the designers (they use dreamweaver/fireworks etc) to design their page, and let some software code it for them (lazy buggers) - the coders - they use web editors/text editors, sometimes with autofillers (they pwn) - the n00bs that use freewebs. They suck. Link to comment https://forums.phpfreaks.com/topic/104742-change-value-in-php-code/#findComment-536231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.