PHP - Submitting Data To Txt File From Textarea
Hey folks,
I thought this would be simple but obviously not. I can get the data to display in the textarea from the text file. That's not an issue. The issue is, updating the text from the textarea and saving it in the file, while keeping the text in the textarea. Basically, I want to create a personal notepad inside the site I am making. Here is the code I am using: <form action="?admintext.txt" method=post> <textarea name="file_content" class="textarea1"><? include "admintext.txt"; ?></textarea><br/> <input type=submit name=submit value=Update> </form> Can anyone help with this? I tried loads of tips I found from Google but none worked. Similar TutorialsSometimes when I submit data to a table (example a blog), it does not get added to the table. I am thinking the reason it has something to do with " / , etc... those kind of symbols, do I need to escape them some how before adding the data to the table? Kindly help. Am a new php programmer and am learning how to HTML form data to a php script. Have tried several times but information on html form never get submitted. For some unknown reasons, the codes are failing . Here are my codes:
<html>
and
<html>
<body> Hello, I am just getting interested in PHP, so please excuse my ignorance. Something I thought might help me learn is this challenge. http://penn-station.com/gift2010.php is a daily enter sweepstakes. I'm wanting to automate a daily entry. I was able to do so using AutoIT (windows automation), but the result was rather janky. Anyways, I found how to enter my name in the Name field of the form by modifying the value attribute of the textbox. (I used Chrome's DOM inspector plug-in) <input type="text" class="EH_Form_Textbox" name="Name" size="30" value="Fred"> How would I go about actually submitting this? Thank you very much, Fred Hello, I'm new to this forum and I need some help. I'm creating a simple database that it submits data from a user input. Unfortunatly, it's not sending any data to mysql also the form is not validating each field. Code: [Select] <?php if (isset($_POST['submitted'])){ $fields = array( 'email', 'state', 'district', 'gender', 'age', 'profession', 'survey', ); foreach($fields as $fieldName) { if(isset($_POST[$fieldName]) and trim($_POST[$fieldName]) !==''){ $fieldName = trim($_POST[$fieldName]); }else { $errors[] = "Please enter your". $fieldName .""; //code to validate fields } } if(isset($errors)){ require_once('Connections/encourage.php'); $query = "INSERT INTO participants (email, state, district, gender, age, profession, survey) VALUES ('$email', '$state', '$district', '$gender', '$age', '$profession','$survey')"; //databasse connection $result = mysql_query ($query); if ($result){ echo '<h1 id="mainhead">Thanks for submitting</hl> <p>You are now registered</p>'; exit(); }else{ echo '<h1 id="mainhead">System Error</hl> <p>Your registration could not be completed due to a system error We apologize for any incovience</p>';//gives system error echo 'p' . mysql_error(). '<br /><br />Query: ' . $query . '</p>'; exit(); } mysql_close(); } else { echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach($errors as $msg) { echo " - $msg<br/>\n"; } echo '</p><p>Please try again.</p><p><br/></p>'; } } ?> <form id="form1" name="form1" method="post" action"registration.php"> <fieldset class="first"> <label class="lableone" for="email">Email:* </label> <input name="email" value="<?php if(isset($_POST['email'])) echo $_POST['name'];?>"/> <label for="state"/>State:* </label> <input name="state" value="<?php if(isset($_POST['state'])) echo $_POST['state'];?>"/> <label for="schooldistrict"/>School District:* </label> <input name="schooldistrict" value="<?php if(isset($_POST['district'])) echo $_POST['district'];?>" /> <label for="gender">Gender:* </label> <select name="gender"> <option>Choose Your Gender</option> <option value="male" <?php echo ($form['gender'] == 'male' ? ' selected' : ''); ?>>Male</option> <option value="female"<?php echo ($form['gender'] == 'female' ? ' selected' : ''); ?>>Female</option> </select> <label for="age"/>Your Age:* </label> <input name="age" type="text" class="age" maxlength="2" value="<?php if(isset($_POST['age'])) echo $_POST['age'];?>" /> <label for="profession"/>Profession:* </label> <input name="profession" value="<?php if(isset($_POST['age'])) echo $_POST['age'];?>" /> <label for="surveys"/>Willingness to participate in future surveys: </label> <input name="surveys" type="checkbox" id="surveys" value="yes" <?php echo ($form['survey'] == 'yes' ? 'checked' : '');?>/> </fieldset> <fieldset> <input class="btn" name="submit" type="submit" value="Submit" /> <input class="btn" name="reset" type="reset" value="Clear Form" /> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> Can someone help me out? Thanks in advanced! Hi Guys I've constructed a modified shopping cart system using the tutorial he http://v3.thewatchmakerproject.com/journal/276/ I'm not great at PHP but have managed to have it working great. My question is: How can I send the data stored in my session, via email using the form? On the final page before the submission is made to email the data - i've got contact detail inputs for the form, and the cart items shown. I just don't know how to send that info onwards. Many thanks.... Hi, I have a dynamic form which uses javascript to add rows on the fly. The name of the element on my test page is txtRow1, txtRow2, etc; the number is added when I add a new row. I am trying to figure out how I will extract the data once the form had been POSTED. I have tried Code: [Select] $tags = $_POST['txtRow']; foreach ($tags as $t) { echo "$t<br />"; } but that shows nothing. I would be grateful for any assistance. Thanks I have looked up tutorials on Google. I am still confused. I built a php script that receives the data from my html form then filters out bad words. I am trying to get the script to resend the data to pm.cgi. The form was originally targeting pm.cgi but it needed filtered. This is why i am using php in the first place. Please help me pass these variables from the php script to the cgi script the same way that a html form would. Thank you. Here is my code, it prints correctly. I cannot get cURL to work. <?php $action = $_GET['action'] ; $login = $_REQUEST['login'] ; $ID = $_REQUEST['ID'] ; $text = $_REQUEST['Unused10'] ; $submit = $_REQUEST['submit'] ; function filterBadWords($str){ // words to filter $badwords=array( "badword1", "badword2"); // replace filtered words with random spaces $replacements=array( "****", "***", "****" ); for($i=0;$i < sizeof($badwords);$i++){ srand((double)microtime()*1000000); $rand_key = (rand()%sizeof($replacements)); $str=eregi_replace($badwords[$i], $replacements[$rand_key], $str); } return $str; } $text = filterBadWords($text); print_r($action); print_r($login); print_r($ID); print_r($text); print_r($submit); ?> I need to send the variables that i printed above to pm.cgi. Can you point me in the right direction? Thanks again! What's wrong with this code? Code: [Select] <textarea name="description" cols="60" rows="10"><?= $description ?></textarea> The textarea box returns null. I have a form where people have to fill in some fields and send an email. When there is an error the user has to go back to the form with: Code: [Select] if (!isset($_POST['checkbox'])) { $msgToUser = '<br /><br /><font color="#FF0000">You did not add any recipients!<br><a href="javascript: history.go(-1)">Go Back</a></font>'; include_once 'msgToUser.php'; exit(); } I want to save the data that has been filled in the textarea so he doesn't have to type eveything again. I tried several options but the textarea keeps getting blank. Code: [Select] <?php $message = isset($_POST['message']) ? $_POST['message'] : ''; $fhtml = "<p>Welcome <b>'$logOptions_username'</b> write your email here. <a href=\"#\" onclick=\"return false\" onmousedown=\"javascript:toggleViewFlags('country_flags');\">Add Recipients</a> <br> </p><input type=hidden name=post value=yes><p> Subject:<br> <input type=text name=name size=100> </p> <p> Message:<br> <textarea name=message rows=10 cols=75>$message</textarea> </p> <p> <input type=submit name=submit value=\"Send\"> $sendMsg </p> "; echo $fhtml; ?> This code is apparently not working. Marco Hello everyone! I've been on a problem a few hours now and I've managed to finally find the solution however I feel it's very inefficient and am looking for a way to do this in a better way. I have a textarea where each line is inserted into MySQL database table "lines" and I have the columns "line_number" and "row". The textarea initial value on page load is simply a list of all lines ordered by line_number in ASC order. If I modify/add/remove entries from the textarea it will remove data changed and add new data accordingly. But I am making a lot of queries to do this and I'm not sure if there is a more efficient way than querying each line in the database to find the new value/modified value. Here's my php script, hopefully this makes sense:
if (isset($_POST['lines'])) { //get lines posted from textarea $lines_posted = $_POST['lines']; //trim all white spaces and remove empty lines as they are not valid for mysql insert $lines = trim($lines_posted); $lines = explode("\n", str_replace("\r", "", trim($lines_posted))); $lines = array_map('trim', $lines_posted); $lines = array_filter($lines_posted); $line_count = count($lines); //output how many valid lines were posted echo "Posted Lines: $line_count<br>"; //loop through all lines posted, query all rows in database and insert if lines row value does not exist for ($i = 0; $i < $line_count; $i++) { if (isset($lines[$i])) { $find_line_in_db = $db->query("SELECT row FROM lines WHERE row=?", $lines[$i]); if ($find_line_in_db->numRows() == 0) { $db->query("INSERT INTO lines (line_number, row) VALUES (?,?)", $i, $lines[$i]); echo 'Added the line: ', htmlspecialchars($lines[$i]), '<br>'; } } } //query all rows in the database and check if posted lines array value is in the [row] column, delete rows changed/not found accordingly $rows = ""; $fetch_all_lines = $db->query("SELECT row FROM lines"); while ($all_lines = $fetch_all_lines->fetchRow()) { if (!in_array($all_lines['row'], $lines)) { $rows = $all_lines['row']; $db->query("DELETE FROM lines WHERE row=?", $all_lines['row']); echo 'Deleted the line: ', htmlspecialchars($lines[$i]), '<br>'; } } }
So to visualize what I'm doing imagine two arrays:
$lines = ["line1", "line2", "line3changed"] //textarea lines posted $db_lines = ["line1", "line2", "line3"] //$db_lines = the current rows in lines db table // line_number | row // 0 | line1 // 1 | line2 // 2 | line3 //outputs //Added the line: line3changed //Deleted the line: line3
So basically what I'm asking is, am I doing this the right way? I would have over 10,000 lines that would be altered every hour in this table and am unsure if I'm doing it the correct way This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=306916.0 I'm having a problem with some php code that allows you to edit a text file. No matter what file it loads, it always adds four horizontal tabs and two spaces to the end of the text. I've attached the code to this post. If anyone can help me with this, it would be greatly appreciated. Cindy I am trying to create a program to get input from user in textarea and save that input into a text file.
But this code is only creating an empty file.
<?php echo <<<_END <form action="form.php" method="post"> <textarea name="textdata" cols="50" rows="20"></textarea> <input type="submit" name="submit" value="CLICK ME"> <input type="hidden" name="submit_check" value="1"> </form> _END; function write(){ $fname="test.txt"; $fh=fopen($fname,'w'); $data=$_POST['textdata']; fwrite($fname,$data); fclose($fh); } if(isset($_POST['submit_check'])){ write(); } ?>please help me. sorry for bad english Edited by mac_gyver, 24 August 2014 - 12:11 PM. code tags please Hia, I'm having a form, containing an image upload, a textarea and some other fields. I have a fileupload, where I check if the upload thingy is empty, with Code: [Select] if(empty($_POST['image'])) { echo "Error"; } else { //Do the imageUpload here } using the empty, isn't working for some reason, it proceed to the else anyway. Also, I have a textarea with name="productDesc", when I do: Code: [Select] <?php var_dump($_POST); ?> It doesn't return the textarea, and I can't see why it doesn't. Also the textarea proceed to the 'else' in the if else in the following code: http://codepad.org/wMd6SnoK Having a lot of questions these days Thank you guys! I have a textarea and a button, I would like by click a button, the text within the textarea will save as a .txt file and downloadable by user, how to do it with php?? Thanks!! Well, im a n00b for php, and what i need is a php script which will read data from .xml file and write it into .txt file. Can someone help me? Example of .xml file : <?xml version="1.0" encoding="utf-8"?> <tv generator-info-name="NeTXMLTV/1.0.0.0" source-info-url="http://www.net-tv.hr/" source-info-name="NeT TV XMLTV" source-data-url="http://www.net-tv.hr/xmltv/net-pregled-programa-xmltv.xml"> <programme channel="NeT TV" start="20110413063000 +0200" stop="20110413080000 +0200"> <title lang="hr">JUTARNJI EXPRESS</title> <category lang="hr">glazbeno-informativni program</category> <desc lang="hr">Glazbeno informativna emisija sa servisnim informacijama i jutarnjim temperaturama, idealna za jutarnje buđenje uz toplu kavu ili čaj....</desc> </programme> </tv> I need the .txt file to look like this: 201104130630 - 201104130800 JUTARNJI EXPRESS glazbeno-informativni program Glazbeno informativna emisija sa servisnim informacijama i jutarnjim temperaturama, idealna za jutarnje buđenje uz toplu kavu ili čaj.... Can someone please help me? thanks Dear All Members here is my table data.. (4 Columns/1row in mysql table)
id order_no order_date miles How to split(miles) single column into (state, miles) two columns and output like following 5 columns /4rows in mysql using php code.
(5 Columns in mysql table) id order_no order_date state miles 310 001 02-15-2020 MI 108.53 310 001 02-15-2020 Oh 194.57 310 001 02-15-2020 PA 182.22
310 001 02-15-2020 WA 238.57 ------------------my php code -----------
<?php
if(isset($_POST["add"]))
$miles = explode("\r\n", $_POST["miles"]);
$query = $dbh->prepare($sql);
$lastInsertId = $dbh->lastInsertId(); if($query->execute()) {
$sql = "update tis_invoice set flag='1' where order_no=:order_no"; $query->execute();
} ----------------- my form code ------------------
<?php -- Can any one help how to correct my code..present nothing inserted on table
Thank You Edited February 8, 2020 by karthicbabu |