Jump to content

Linebreak in mySQL


lazaruz

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.