Hey all...

I have been using the .nl2br function to automatically add line breaks when entering text into the DB but have recently run into a problem.

I created this page and it works just fine, line breaks and all. I used Dreamweaver MX 2004 for this one...

<?php require_once('../Connections/koboxing.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO ind_content (record_num, content) VALUES (%s, %s)", GetSQLValueString($_POST['record_num'], "int"), nl2br(GetSQLValueString($_POST['content'], "text"))); mysql_select_db($database_koboxing, $koboxing); $Result1 = mysql_query($insertSQL, $koboxing) or die(mysql_error()); $insertGoTo = "success.htm"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../stylesheet.css" rel="stylesheet" type="text/css"> </head> <body> <form name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <p>&nbsp;</p> <table width="800" border="0" align="center" cellpadding="10" cellspacing="0"> <tr bgcolor="#BF6A00"> <td colspan="2" align="left" valign="top"><input name="record_num" type="hidden" id="record_num"> <img src="../images/welcome.jpg" width="408" height="42"></td> </tr> <tr bgcolor="#BF6A00"> <td width="153" align="left" valign="top" class="heading_text">Add your content here: </td> <td width="647" align="left" valign="top"><textarea name="content" cols="75" rows="15" id="content"></textarea></td> </tr> <tr bgcolor="#BF6A00"> <td colspan="2" align="left" valign="top"><div align="center"> <p>&nbsp; </p> <p> <input type="submit" name="Submit" value="Add Content"> </p> </div></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html>

I have since upgarded to Dreamweaver 8 and created this page. Now there are no line breaks, but SHOULD be...

<?php require_once('../Connections/koboxing.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO editorial (edit_rec, edit_content) VALUES (%s, %s)", GetSQLValueString($_POST['edit_rec'], "int"), nl2br(GetSQLValueString($_POST['edit_content'], "text"))); mysql_select_db($database_koboxing, $koboxing); $Result1 = mysql_query($insertSQL, $koboxing) or die(mysql_error()); $insertGoTo = "success.htm"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../stylesheet.css" rel="stylesheet" type="text/css"> </head> <body> <form action="<?php echo $editFormAction; ?>" name="form1" method="POST"> <p>&nbsp;</p> <table width="800" border="0" align="center" cellpadding="10" cellspacing="0"> <tr bgcolor="#BF6A00"> <td colspan="2" align="left" valign="top"><input name="edit_rec" type="hidden" id="edit_rec"> <img src="../images/editorial.jpg" width="408" height="42" lowsrc="../images/editorial.jpg"></td> </tr> <tr bgcolor="#BF6A00"> <td width="153" align="left" valign="top" class="heading_text">Add your content here: </td> <td width="647" align="left" valign="top"><textarea name="edit_content" cols="75" rows="15" id="edit_content"></textarea></td> </tr> <tr bgcolor="#BF6A00"> <td colspan="2" align="left" valign="top"><div align="center"> <p>&nbsp; </p> <p> <input type="submit" name="Submit" value="Add Content"> </p> </div></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html>

Both pages are used to add content to the database but to different tables.

I am STUMPED....

Thanks in advance....

    just a shot in the dark but you could try

    GetSQLValueString(nl2br($_POST['edit_content']), "text"));

      Brilliant!!

      Worked like a charm!!!!
      THANK YOU!!

        Write a Reply...