PHP - Textarea Code Adds Unwanted Extra Data To The End
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 Similar TutorialsHey Guys, I've got a small script that displays latest news. It is supposed to show just the title of the news item in a list, however it shows the content at the bottom of the code... This is my page <ul> <?php $args= array( 'news_items' => 500, 'title' => TRUE, 'content' => FALSE, 'before_title' => '<li>', 'after_title' => '</li>' ); jep_latest_news_loop($args); echo '</ul>'; ?> <br>TEST<br> But this is the output Quote * February 2011 Newsletter * January 2011 Newsletter * December 2010 Newsletter * November 2010 Newsletter * October 2010 Newsletter * New Website Launched TEST February 2011 Newsletter January 2011 Newsletter December 2010 Newsletter November 2010 Newsletter October 2010 Newsletter XXX XXXXX are pleased to announce the launch their new website today. We hope you find it easy to use and informative. Please feel free to contact us with any queries. This is the code generator page <?php add_action('init', 'jep_latest_news_init'); function jep_latest_news_init() { // Create new Latest-News custom post type $labels = array( 'name' => _x('Latest News', 'post type general name'), 'singular_name' => _x('Latest News', 'post type singular name'), 'add_new' => _x('Add New', 'Latest News'), 'add_new_item' => __('Add New Latest News'), 'edit_item' => __('Edit Latest News'), 'new_item' => __('New Latest News'), 'view_item' => __('View Latest News'), 'search_items' => __('Search Latest News'), 'not_found' => __('No Latest News found'), 'not_found_in_trash' => __('No Latest News found in Trash'), '_builtin' => false, 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => 20, 'supports' => array('title','editor','author','thumbnail','excerpt','comments'), 'taxonomies' => array('category', 'post_tag') ); register_post_type('latest-news',$args); } /* Template function to output the latest news stories */ function jep_latest_news_loop($args = null) { $defaults = array( 'news_items' => 500, 'title' => TRUE, 'content' => FALSE, 'before_title' => '<li class="h3">', 'after_title' => '</li>', ); global $paged; $r = wp_parse_args( $args, $defaults ); $qargs=array( 'post_type'=>'latest-news', //'posts_per_page' => $r[news_items], //'paged' => $paged ); query_posts($qargs); while ( have_posts() ) : the_post(); ?> <?php echo($r[before_title]);?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php echo($r[after_title]);?> <?php endwhile; } ?> Any ideas what is dumping the extra code? Can anyone tell me what's making this code put an extra entry in the database?Whatever the number of looped students being added, it adds another row with nothing but the registrationid entered. Code: [Select] <?php // connect to database include("databaseconn.php"); // store all posted intemnos and descriptions in local arrays $fname = $_POST['fname']; $lname = $_POST['lname']; $phone = $_POST['phone']; $email = $_POST['email']; $bdate = $_POST['bdate']; $bdate2 = $_POST['bdate2']; $bdate3 = $_POST['bdate3']; $wid = $_POST['wid']; $rid = $_POST['reg_id']; $reg_alone = $_POST['reg_alone']; $_SESSION['workshops']=$wid; ?> <? if(sizeof($_POST['fname'])) { // loop through array $number = count($fname); for ($i=0; $i<=$number; $i++) { // store a single item number and description in local variables $fnames = $fname[$i]; $lnames = $lname[$i]; $phones = $phone[$i]; $emails = $email[$i]; $bdates = $bdate[$i]; $bdates2 = $bdate2[$i]; $bdates3 = $bdate3[$i]; $wids = $wid[$i]; $rids = $rid[$i]; echo "echod ".$bdates2."and<br>"; print_r($bdates2); $query_insertItemWorkshop = "INSERT INTO tbl_attendees (attendee_fname, attendee_lname, attendee_registrationid, workshop_id, attendee_email, attendee_telephone, attendee_bday, attendee_bmonth, attendee_byear) VALUES ('$fnames', '$lnames', '$reg_alone', '$wids', '$emails', '$phones', '$bdates', '$bdates2', '$bdates3')"; echo "query: ".$query_insertItemWorkshop; $dberror = ""; $ret = mysql_query($query_insertItemWorkshop); } } ?> I have this query which query the parent.name and the node.name as well. Code: [Select] "SELECT parent.name FROM categories AS node, categories AS parent WHERE node.left_node BETWEEN parent.left_node AND parent.right_node AND node.name = '{$node_name}' ORDER BY parent.right_node AND node.left_node" below in the foreach loop is displaying both the node and parent, I only need the parent. I have done a little if statement saying that if node.name not to display but didn't work because both parent.name and node.name are displaying the he same field name. Code: [Select] <?php foreach($iterator as $key=>$value) { if($value <> "node.name") echo $value.'<br />'; } ?> Hi all. Here is the code:(thanks to jcbones) Code: [Select] if (($handle = fopen($source_file, "r")) !== FALSE) { $columns = fgetcsv($handle, $max_line_length, ","); foreach ($columns as &$column) { $column = str_replace(".","",$column); } while (($data = fgetcsv($handle, $max_line_length, ",")) !== FALSE) { while(count($data) < count($columns)) { array_push($data, NULL); } $c = count($data); for($i = 0; $i < $c; $i++) { $data[$i] = "'{$data[$i]}'"; } $sql[] = '(' . implode(',',$data) . ','.$_POST[group].')'; } $sql = implode(',',$sql); $query = "INSERT INTO mytable (".mysql_real_escape_string(implode(",",$columns)).",Custgroup,user_id) VALUES " . $sql . "\n"; mysql_query($query) or trigger_error(mysql_error()); fclose($handle); } } If my csv file is: lastname,firstname,gender bob,ah,male So now the query will be : INSERT INTO mytable (lastname,firstname,gender) VALUES ('bob',ah','male'). But how if I want to insert extra data into mysql together with the data in csv file? Such as I have a value $_POST['group'] = 'family', so I tried: Code: [Select] $sql[] = '(' . implode(',',$data) . ','.$_POST[group].')'; $query = "INSERT INTO $target_table (".mysql_real_escape_string(implode(",",$columns)).",custgroup) VALUES " . implode(',',$sql) . "\n"; But in the query it will become : INSERT INTO mytable (lastname,firstname,gender,custgroup) VALUES ('bob',ah','male',family). It didn't have single quote , so I have error to insert the record.Can I know how to solve this problem? Thanks. I have 2 files; Newfault.php and thankyou.php 1) Data is entered into a form in Newfault.php 2) The data from this form is retieved in thankyou.php and is then inserted into a table called "Calls" Problem: My entered record is being added to my database OK, but it is also adding a blank record for some reason and I can't work out why. Can anyone help? This is for my uni assignment. Thanks, Ladykudos 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 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. 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 Hi I have a text area, that I want to display info pulled from a database. I can get the data to show, But can get each entry of the table to display on it's own line. Example: ob1ob2ob3ob4ob5 Should be: ob1 ob2 ob3 ob4 ob5 CODE: Code: [Select] <textarea id="interest" onfocus="clearInterest()" class="textareacss" style="height:212px;overflow:auto;"><?PHP $newInterestSub = Admin_interests_sub::find_by_cat_id($id); foreach($newInterestSub as $newInterestSubs){ echo $newInterestSubs->interest_sub.'\n'; } ?></textarea> Any help would be great. Hello dear friends, If i've database table (my_table) with one field (text) and i've created form with textarea Code: [Select] <form action="#"> <textarea name="text" id="text"></textarea> <input type="submit" name="Submit" value="Submit"> </form> I can add any text inside it and save it in my database table but when i add html codes it also store it perfect but only 2 codes is not the closing of form and textarea </form> and </textarea> it not stored and automatically not saved Why ! i mean if i paste inside the above form - textarea the following code for example Code: [Select] <form> <textarea>blah</textarea> </form> it will store it as Code: [Select] <form> <textarea>blah and will not store </form> and </textarea> how then i can add html codes with textarea and form inside it without conflict thanks I have a php form in which ,on click of a edit button the contents of that table row will be displayed in a text area (which appears on the click of that edit button).Below the textarear i have a submit and delete button,i can perform any action.Ater performing the save or delete click the text area should be hidden. this is not happening,tried with js also. pasting the code below Code: [Select] <form name='add_title' method='post' action=''><?php echo "<br><br>"; if(isset($_POST['update'])) { if(isset($_GET['id'])) { $id = $_GET['id']; $comments=$_POST['comment']; $query1 = "update comments set comments='$comments' WHERE id = '$id' "; $result = mysql_query($query1); //$row=mysql_fetch_row($result); } } if(isset($_POST['delete'])) { if(isset($_GET['id'])) { $id = $_GET['id']; $comments=$_POST['comment']; $query1 = "delete from comments WHERE id = '$id' "; $result = mysql_query($query1); } } $query="select count(*) from comments"; $result =mysql_query($query); $row=mysql_fetch_row($result); $count= $row[0]; if($count!=0) { $query="select *from comments order by id desc"; $result=mysql_query($query); echo "<table width='700' align='center' border=1><tr bgcolor='green' align='center'><td><font color='black'> SlNo </font></td><td><font color='black'>Comment</font></td><td><font color='black'> Date Posted </font></td><td>Edit/Delete</td></tr></b>"; while($row = mysql_fetch_row($result)) { $d=$row['0']; $id=$row['0']; $name=$row['1']; $date_uploaded=$row['3']; echo "<td>$id</td><td>$name</td>". "<td>$date_uploaded</td>". "<td><a href='edit_comments.php?id=$id'>Edit </a></td>". "</tr>"; } if(isset($_GET['id'])) { $id = $_GET['id']; $query = "SELECT comments FROM comments WHERE id = '$id' "; $result = mysql_query($query); $row=mysql_fetch_row($result); echo"<center><table width='700' border='1'><tr><td > <textarea name='comment' cols='80' rows='10'>$row[0]</textarea> <td></tr><tr><td><a href='edit_comments.php?id=$id'><input type='submit' name='update' id='update' value='Save'></a><a href='edit_comments.php?id=$id'><input type='submit' name='delete' id='delete' value='Delete'></a> </td><td></td></center>"; } echo "</table>"; } else { echo "<table width='700' align='center'><tr bgcolor='white' align='center'><td><font color='red' size=2>No comments for you.</font></td></tr></table>"; } ?> Edit: Please use [code][/code] tags when posting code. hi, I have some HTML to edit in my database, in my back end administration I have it in a textarea but when I go to edit it, it all messes up and lots of '/' area added, see below: Code: [Select] Site Design by: <a href=\\\\\\\"http://www.jbiddulph.com\\\\\\\" target=\\\\\\\"_blank\\\\\\\" title=\\\\\\\"John Biddulph - Web Development\\\\\\\">jbiddulph.com</a> php code Code: [Select] <p> <label>Site Design by</label> <textarea class="text-input small-input" name="SiteDesignby"><?php echo $row1['SiteDesignby'] ?></textarea> </p> someone suggested adding this to my page: SiteDesignby.value = SiteDesignby.value.replace(/\\*."/g,'"'); I added the code and nothing changed! Can anyone help please? 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>subject. Why does it do this and how can I fix it? Example: I write <?php echo"hello world!"; ?> other stuff/html here After I submit I see this: <?php echo"hello world!"; ?> other stuff/html here 1 I'm using Geshi w/ highlight_string This also happens if I use htmlspecialchars + highlight_string I'm trying to automatically change a math equation so that the solution is an even number: It is at first complicated but I'm progressing. This is my first attempt at accomplishing what I'm trying to accomplish. if (($sol != round($sol)) && ($x1 < $x2)) { /***********************************************************/ function round_up ($sol, $x1, $op, $x2) { for ($x1 = $x1; $sol < round($sol); $x1++) { switch ($op) { case '+' : $sol = $x1 + $x2; break; case '-' : $sol = $x1 - $x2; break; case '*' : $sol = $x1 * $x2; break; case '/' : $sol = $x1 / $x2; break; } } return (array ($sol, $x1, $op, $x2)); } /**********************************************************/ $round_array = round_up($sol, $x1, $op, $x2); echo "after for loop: $round_array[1] $round_array[2] $round_array[3] = and sol: $round_array[0] <br /><br />"; } If the solution of the equation is not a round number, and if the first number is smaller than the other, than increase the first number until the solution is a round number. It is a very primitive solution, but I'm learning as I go and I'll try to make it more intelligent. But to my problem, the above script outputs following values: Code: [Select] first calc: 3 / 5 = ? first sol: 0.6 after for loop: 6 / 5 = and sol: 1 The script will increase the first number about 1 digit more, and that is exactly my problem, since that way the equation makes no sense. The condition of the for loop is, increase $x1 till $sol is SHORTLY before the next rounded number, when it is has reached the next rounded number STOP. Thus $x1 should be 5 in the above example, because 5/5 = 1. IT seems that after $sol has reached the next round number, the for loop will go one more time over the variables, and THEN it will stop. How can I solve this problem? I have a form that generates html code, and displays it in a textarea with submit button. I want to submit button to take the data entered in that textarea1 on page 1, and upload to textarea2 on page 2 How can I do this? I have no idea where to start. |