Search the Community
Showing results for tags 'write'.
-
Hey guys! I have a page that has multiple forms. I am trying to make a button that will save all the information from each textarea to a different .txt file. IE: textarea1 will save to textarea1.txt textarea2 will save to textarea2.txt textarea3 will save to textarea3.txt etc. I am able to save each individual form via individual submit buttons within each form, but I'd like to make a submit button outside of the other forms that saves all forms to their specific files. The code for one of the individual forms looks like this: <form method="post" action="?"> <h1>Physical Stats</h1> <textarea name="stats"><?php include ('resources/stats.txt'); ?></textarea> <br><input type="submit" name="update_stats" value="Update"/> </form> <?php if (isset($_POST['update_stats'])) { file_put_contents("resources/stats.txt", $_POST['stats']); } ?> Everything above works. And the code for the save all form looks like this: <form method="post" action="?"> <input type="submit" name="update_all" value="Update All"/> <br><br> </form> <?php if (isset($_POST['update_all'])) { file_put_contents("resources/stats.txt", $_POST['stats']); file_put_contents("resources/pro_exp.txt", $_POST['pro_exp']); file_put_contents("resources/pro_awards.txt", $_POST['pro_awards']); file_put_contents("resources/ama_exp.txt", $_POST['ama_exp']); file_put_contents("resources/ama_awards.txt", $_POST['ama_awards']); file_put_contents("resources/references.txt", $_POST['references']); } ?> This is the code I currently have and it's just not working. Right now the above code is actually clearing all of the text files. I'm afraid I'm a complete newb to writing scripts and I'm sure there is some rule about file_get_contents that I'm not aware of. Please help! Thanks!
-
Hello! l was wondering if you might be able to help me. l am trying to find out how to make PHP read a file, and then check if that text is already there, and if so don't re-write it. l'll give out my code for an example. <?php //text file that counts the peeps that visit the site $lne = "line.txt"; $File = "counter.txt"; $handle = fopen($File, 'r+') ; //file open $data = fread($handle, 512) ; //file read $count = $data + 1; //Adds one person :DDDDD fseek($handle, 0) ; fwrite($handle, $count) ; //saves the new person echo 'Count #'.$count; // // // // // // $File2 = "ips.txt"; fclose($handle) ; if (isset($_POST['ip'])) { $ip = $_POST['ip']; $port = $_POST['port']; echo 'Connecting to ' . $ip . ':' . $port; exit(); } $ip = getenv("REMOTE_ADDR"); echo '<br>'.$ip; $handle2 = fopen($File2, 'r+') ; //file open $data2 = fread($handle2, 512) ; //file read fwrite($handle2,"\n" . $ip .':' . $count); //saves the new ip ?> <html> <form method="POST"> <input type="hidden" name="ip"> <input type="hidden" name="port"> </html> lt just re-writes the lP with the new counter, very annoying. l can filter it out with VB but l want it all to be server sided. Thank you for your time ~Papa Beans
-
I hate to ask for help for my first, but I am currently having issues writing out a code for a program in progress. Basically, I am not great at php, but I need a code that will store information when sent to it from the program itself. I am setting it up to store login information, so the program writes out (lets say the username), when the person clicks the 'Next' button, it sends it to the .php and the .php will write that certain file out with the username as the .txt file name. I have this so far, if someone could figure out the code, that would be amazing. Thanks! <?php $msg = $_GET['w']; $logfile= (['username.txt'); $fp = fopen($logfile, "a"); fwrite($fp, $msg); fclose($fp); ?>
-
Hello I'm having a problem with my php script. It's about writing lines to a text file. The script runs normally without any errors, but it leaves the text file empty, no matter how many times I run it. I'm using WAMP server. Here's the code: <?php //kratke varijable $tireqty=$_POST['tireqty']; $oilqty=$_POST['oilqty']; $sparkqty=$_POST['sparkqty']; $adress=$_POST['adress']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; $date = date('H:i, jS F Y'); ?> <html> <head> <meta charset="utf-8"> <title>Bob's Auto parts - Order results</title> </head> <body> <h1>Bob's Auto Parts</h1> <h2> Order Results</h2> <?php echo "<p>Order processed at ".date ('H:i, jS F Y')."</p>"; echo "<p>Your order is as follows: </p>"; $totalqty=0; $totalqty=$tireqty+$sparkqty+$oilqty; echo "Item ordered: ".$totalqty."<br />"; if ($totalqty == 0) { echo "You didn't order anyting from previous page!<br />"; } else { if($tireqty>0) echo $tireqty." tires<br />"; if($oilqty>0) echo $oilqty." oil<br />"; if($sparkqty>0) echo $sparkqty." sparks<br / >"; } $totalamount=0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; echo 'Subtotal: $'.number_format($totalamount,2).'<br />'; $taxrate = 0.20; // local sales tax is 20% $totalamount = $totalamount * (1 + $taxrate); echo 'Total including tax: $'.number_format($totalamount,2).'<br />'; echo '<p>Adress to ship to is '.$adress.'</p>'; $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t" .$sparkqty." spark plugs\t\$".$totalamount ."\t". $adress."\n"; //open file for appending @ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); if(!$fp) { echo "<p><strong> Your order could not be processed at this time.<br> Please try again later. </strong></p></body></html>"; exit; } flock($fp, LOCK_EX); echo fwrite($fp, $outputstring, strlen($outputstring)); flock($fp, LOCK_UN); fclose($fp); echo "<p>Order written.</p>"; ?> </body> </html> Thanks in advance for any help.