Hightower Posted October 22, 2008 Posted October 22, 2008 I'm just fiddling with a bit php that adds some data from a form to a mysql database. At the same time this form is submitted I want to add the same data to a text file. Can anybody help me with how to achieve this?
localzuk Posted October 22, 2008 Posted October 22, 2008 This should tell you how to do it: PHP Tutorial - File Write 1
Hightower Posted October 23, 2008 Author Posted October 23, 2008 Cheers localzuk. The file goes back to itself when submitted so the user can submit something different straight away. As confirmation of submitting the previous one successfully I was wanting to put something like: You have successfully added $string How would I go about doing this?
budgester Posted October 23, 2008 Posted October 23, 2008 Can you post some code to show how far you have got, then we can help you.
Hightower Posted October 23, 2008 Author Posted October 23, 2008 I have a form on a page with a field called 'txtTitle'. When this form is submitted it adds that info to a database and then goes back to the same page so they can add something again. All I want is to show what they have just added so they know they have been successful. Something like print $txtTitle I don't want to post code because I'm a little ashamed of it. Any help is appreciated
tmcd35 Posted October 23, 2008 Posted October 23, 2008 I wouldn't be ashamed of your code - you should see the horror that is some of mine! I think there a generally two ways of doing what you want, if I understand it correctly. The first is to use a cookie or session to pass a couple of variables - a flag and the submitted text. You could then reload the page, check the flag and if flag = 1 then flag = 0 print $string end if Or, the other way is to do it with out reloading the page. This would require some Javascript. Javascript can pick up an onClick() event on the submit button and can be used to print the success command to the screen. I'd probably use the first method myself along with a test to make sure they were successful. 1
My220x Posted October 23, 2008 Posted October 23, 2008 I would store the input data in a variable so like: $datasent = $_POST["txtTitle"]; I would then have: print $datasent; This should solve your problem. 1
CESIL Posted October 23, 2008 Posted October 23, 2008 I would store the text entered in a session variable, adding each new text entry to it. This can then be printed when the page reloads giving an audit trail of all text entered in that session.
My220x Posted October 23, 2008 Posted October 23, 2008 I would store the text entered in a session variable, adding each new text entry to it. This can then be printed when the page reloads giving an audit trail of all text entered in that session. Hightower said he/she wanted to print out what they have just entered not everything they have entered in that session.
Hightower Posted October 23, 2008 Author Posted October 23, 2008 Thanks for all the help so far - I'm getting there. I have just one thing left to do, and need help again. I have managed to open, append and close a text file in the same location of the php files, but now need to open, append and close a text file that is stored on a different server. Can anybody help me? The code I have so far for this bit is: $myFile = "whitelist.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = $_POST['txtAddress']; fwrite($fh, $stringData); fwrite($fh, "\r\n"); fclose($fh); The whitelist.txt bit needs to be pointing to \\SERVER\SHARE\whitelist.txt Thanks,
Hightower Posted October 23, 2008 Author Posted October 23, 2008 I've tried doing that - I mapped it to G: and put in place G:\whitelist.txt but it said it had failed to open the file.
browolf Posted October 23, 2008 Posted October 23, 2008 hmm a quick google says writing to windows network drives from php is massively problematic. you could maybe call up a local batch file that do the copying for you. or stick ftp on server so you can php > ftp instead.
Hightower Posted October 23, 2008 Author Posted October 23, 2008 There's got to be a better way surely?
localzuk Posted October 23, 2008 Posted October 23, 2008 You need to give the IIS user (ie. whatever user IIS and PHP are running as) permission to access the directory on that path.
Hightower Posted October 23, 2008 Author Posted October 23, 2008 How do I find out which user that is?
localzuk Posted October 23, 2008 Posted October 23, 2008 How do I find out which user that is? Err. In the Services administrative tool, look at the settings for the 'World Wide Web Publishing Service?'. It is probably 'Local System Account' - whatever that may be... 1
Hightower Posted October 23, 2008 Author Posted October 23, 2008 I thank you all. It's all sorted now and that's thanks to you lot. What would I do without this place....
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now