FaTTzZO Posted October 17, 2006 Share Posted October 17, 2006 hello thereim new here, and ive search the forums trying to find and answer to my problem, but i didnt find any :Pso here is my problem.i have a form that submits data to mySQL, and i want to switch to <BR> when you hit enter, so i did this[code] $description = $_POST['description']; $description = str_replace("","<br>","$description");[/code]and it works, but now i have a form that edits the Description, but when i get the data from mySQL i get the info and the <BR> codes. so when i submit the form again to edit something it uploads 2 <BR>.what i want is to get the data form mySQL but i want it to appear without the <BR>, ive tried:[code] $description = $_POST['description']; $description = str_replace("<br>","","$description");[/code] before i call the edit form. but that doesnt works :S im kinda lost :Pi need help please.thank you =-]excuse my english, is not leet :P Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/ Share on other sites More sharing options...
Ninjakreborn Posted October 17, 2006 Share Posted October 17, 2006 That will workstr_replace()just trap all the incoming content in a variable, run it through string replace, replace <br />with notags or something Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/#findComment-110218 Share on other sites More sharing options...
kenrbnsn Posted October 17, 2006 Share Posted October 17, 2006 You want to use the function [url=http://www.php.net/nl2br]nl2br()[/url] when you display the value on the browser. Leave it alone when storing in the DB.Ken Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/#findComment-110219 Share on other sites More sharing options...
FaTTzZO Posted October 18, 2006 Author Share Posted October 18, 2006 look this is the code im using to upload the data[code]<?phpif($_POST['Submit']){include("sql.php");$name = $_POST['name'];$description = $_POST['description'];$description = str_replace("","<br>","$description");$ok = mysql_query("INSERT INTO `table` ( `id` , `name` , `description`)VALUES ('NULL', '$name', '$description');");[/code]so when someone use "Enter", it transform that "Enter" into a <BR>now i want to add an edit form, so i can edit de description, ok?but when i call the form and the data it shows me the "Enter" and the <BR> and i want to get rid of the <BR> cuze if i dont and i submit the data, now it multiply the <BR> and insted one i got <BR><BR> :|so i did[code] <? $description = str_replace("<br>","","$description"); ?> <td align="right">Description:</td> <td align="left"><textarea name="description" cols="60" rows="10" class="box" id="description"><?=$description;?></textarea></td>[/code]but that dont works :|, now i dont know what to do :P im learning php. maybe its a silly question, but i cant find the answer.thank you Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/#findComment-110880 Share on other sites More sharing options...
kenrbnsn Posted October 18, 2006 Share Posted October 18, 2006 Do not do the str_replace when you store the description, use the nl2br() function when you display it:[code]<?phpif($_POST['Submit']){include("sql.php");$name = mysql_real_escape_strimg(stripslashes($_POST['name']));$description = mysql_real_escape_string(stripslashes($_POST['description'])); //escape dangerous characters$query = "INSERT INTO `table` ( `id` , `name` , `description`) VALUES ('NULL', '$name', '$description')";$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); ?>[/code]When you want to display the value:[code]<td align="right">Description:</td> <td align="left"><textarea name="description" cols="60" rows="10" class="box" id="description"><?php echo nl2br($description);?></textarea></td>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/#findComment-110896 Share on other sites More sharing options...
FaTTzZO Posted October 18, 2006 Author Share Posted October 18, 2006 thx for your quick reply. but it is now working :(ive replace the functions you said.but now when y type something like this[quote]thisisatest[/quote]i get something like this[quote]thisisatest[/quote]now, when i open the edit form, i get[quote]this(br /)is(br /)a(br /)test(br /)[/quote][i]i dont type br with <> cuze the forum will put a new line :P[/i]what i want, is something like this forum :Pi want to type[quote]thisisatest[/quote]and when i query the result i want to see[quote]thisisatest[/quote]and when i query the value into the edit form, i want to see[quote]thisisatest[/quote]so i can edit it with no problems ;)thx in advance Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/#findComment-110912 Share on other sites More sharing options...
sanfly Posted October 18, 2006 Share Posted October 18, 2006 Lets go over this from the start.When you take data directly from the the form and store in the database, line breaks are "remembered" in the code. You dont need to add them at allWhen you want to display in normal HTML, you use nl2br() to add the linebreaks etc back inIf you are displaying the information in a textarea again, DONT use nl2br, just put the data in directly from the database Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/#findComment-110918 Share on other sites More sharing options...
FaTTzZO Posted October 19, 2006 Author Share Posted October 19, 2006 ooohhhhh... ok... thank you pretty much. and all of you guys ^_^ =-] :D :D :D :D :D :D :D :D :D :D Quote Link to comment https://forums.phpfreaks.com/topic/24251-how-to-get-rid-of-the-code-on-a-form/#findComment-111295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.