lazaruz Posted February 9, 2008 Share Posted February 9, 2008 I have one form which adds data to mysql and one form on another page which retrieves the data and autofills the forms textboxes. This works but only as long as the data in my db doesn't contain any linebreaks, why is that? I'm using this code and calls FillForm and it works for all except $data['long_description'] which have linebreaks in it, the data type for all of them is TEXT <?php function FillForm($id) { $app = mysql_query("SELECT short_description, long_description, whats_new, screen1, screen2, screen3, screen4 FROM cs_applications, cs_screens WHERE cs_applications.id={$id} && cs_screens.application_id=cs_applications.id"); $data = mysql_fetch_array($app); echo "<script> addText(document.form1.screen1, '{$data['screen1']}'); addText(document.form1.screen2, '{$data['screen2']}'); addText(document.form1.screen3, '{$data['screen3']}'); addText(document.form1.screen4, '{$data['screen4']}'); addText(document.form1.short_desc, '{$data['short_description']}'); addText(document.form1.long_desc, '{$data['long_description']}'); </script>"; } ?> <script language="Javascript" type="text/javascript"> function addText(textbox, text ) { textbox.value = text; } </script> Link to comment https://forums.phpfreaks.com/topic/90201-linebreak-in-mysql/ Share on other sites More sharing options...
kenrbnsn Posted February 9, 2008 Share Posted February 9, 2008 Look at the function nl2br(). Ken Link to comment https://forums.phpfreaks.com/topic/90201-linebreak-in-mysql/#findComment-462535 Share on other sites More sharing options...
lazaruz Posted February 9, 2008 Author Share Posted February 9, 2008 If I use nl2br() the text prints well formated if I use the line below, but I still can't add $long to the TextArea $long = nl2br($data['long_description']); echo $long; Link to comment https://forums.phpfreaks.com/topic/90201-linebreak-in-mysql/#findComment-462540 Share on other sites More sharing options...
kenrbnsn Posted February 9, 2008 Share Posted February 9, 2008 Add the nl2br() into your echo statement: <?php echo "<script> addText(document.form1.screen1, '{$data['screen1']}'); addText(document.form1.screen2, '{$data['screen2']}'); addText(document.form1.screen3, '{$data['screen3']}'); addText(document.form1.screen4, '{$data['screen4']}'); addText(document.form1.short_desc, '{$data['short_description']}'); addText(document.form1.long_desc, '" . nl2br($data['long_description']) . "'); </script>"; ?> But why are you using Javascript to do this, when you can use PHP to put the data into the form? Ken Link to comment https://forums.phpfreaks.com/topic/90201-linebreak-in-mysql/#findComment-462588 Share on other sites More sharing options...
lazaruz Posted February 9, 2008 Author Share Posted February 9, 2008 No,that didn't do it... How do you mean I should use php instead? I have a drop-down list and when I select something I want to fill the form based on that value without having to reload the page Link to comment https://forums.phpfreaks.com/topic/90201-linebreak-in-mysql/#findComment-462738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.