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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.