Hey everyone,

PHP and MYSQL newbie here.....can really use your help right now. I implemented a Submodal into my script, and finally got it to submit "User Notes" into the database. Unfortunately with each new submission, the text that is submitted overwrites the previous submission. I was told to use CONCAT_WS to prevent that from happening...I have been trying for several hours on Dreamweaver to accomplish that but it's not working. Here is my code for that section...

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "lead_note_form")) {
  $updateSQL = sprintf ("UPDATE Leads SET Notes = CONCAT_WS('\n', Notes, '$Notes') WHERE Id=%s",
                       GetSQLValueString($_POST['Notes'], "text"),
                       GetSQLValueString($_POST['Id'], "int"));

Please help, would really appreciate it!!! Thank you!!

try to do without sprintf,

$notes=addslashes($_POST['Notes']);
$updateSQL = "UPDATE Leads SET Notes = CONCAT_WS(Notes,'\r\n', '{$notes}') WHERE Id='{$_POST['Id']}'";

You are awesome! I have been working on it all day and no dice! Still a small problem; this is what the code looks like;

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "lead_note_form")) {
$notes=addslashes($_POST);
$updateSQL = "UPDATE Leads SET Notes = CONCAT_WS(Notes,'\r\n', '{$notes}') WHERE Id='{$_POST}'";

For some reason, this is what gets outputted from my submodal box...testing 12345testing 11214124124124124 (They are saving and outputting on the same line.....)

try to do without sprintf,

$notes=addslashes($_POST['Notes']);
$updateSQL = "UPDATE Leads SET Notes = CONCAT_WS(Notes,'\r\n', '{$notes}') WHERE Id='{$_POST['Id']}'";

You are awesome! I have been working on it all day and no dice! Still a small problem; this is what the code looks like;

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "lead_note_form")) {
$notes=addslashes($_POST);
$updateSQL = "UPDATE Leads SET Notes = CONCAT_WS(Notes,'\r\n', '{$notes}') WHERE Id='{$_POST}'";

For some reason, this is what gets outputted from my submodal box...testing 12345testing 11214124124124124 (They are saving and outputting on the same line.....)

Still a small problem

I am not able to understand your problem.

I updated the code. This code works..my question is, what can I change to not stack each submission on top of each other, and give them some spaces in between one another.

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "lead_note_form")) {
$updateSQL = sprintf ("UPDATE Leads SET Notes = CONCAT_WS('\n', Notes, %s) WHERE Id=%d",
GetSQLValueString($_POST, "text"),
GetSQLValueString($_POST, "int"));

two lines after note and then add current note

CONCAT_WS( Notes,'\r\n\r\n', %s)

then when you display note in html page. you may use
nl2br function to convert new line to html break
<?php
echo nl2br ($note);
?>

It's not working, I am getting this error when I am putting the nl2br function; Notice: Undefined variable: note in /home/content/02/8116402/html/test6.php on line 105

you must replace $note with variable of your data fetch array

This is the code, I don't see it.....


<?php
error_reporting(E_ALL);
ini_set('display_errors','On');


?>
<?php require_once('Connections/cms.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET)) {
$pageNum_Recordset1 = $_GET;
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_cms, $cms);
$query_Recordset1 = "SELECT * FROM Leads ORDER BY Id ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $cms) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET)) {
$totalRows_Recordset1 = $_GET;
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" type="text/css" href="subModal.css" />
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="subModalsource.js"></script>
<script type="text/javascript">setPopUpLoadingPage('loading.html');</script>
</head>

<body>
<table class="t1" border="1" align="center" >
<tr>
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Address</td>
<td align="center">City</td>
<td align="center">State</td>
<td align="center">Zip</td>
<td align="center">Phone</td>
<td align="center">Email</td>
<td align="center">Fee</td>
<td align="center">Referral Source</td>
<td align="center">Notes</td>
<td align="center">Edit</td>
<td align="center">Add</td>
</tr>
<?php do { ?>
<tr>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><?php echo $row_Recordset1; ?></td>
<td align="center"><a href="test5.php?Id=<?php echo $row_Recordset1; ?>" class="submodal"><img src="Images/editnote.png" /></a></td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>


</body>
</html>


<?php
mysql_free_result($Recordset1);
?>

You are displaing link to note, where and how you display note?

<a href="test5.php?Id=<?php echo $row_Recordset1['Id']; ?>" class="submodal"><img src="Images/editnote.png" /></a>

This is the code for the note......

<?php
include('lock.php');
?>
<?php echo $login_session; ?>
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
<?php require_once('Connections/cms.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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_update"])) && ($_POST["MM_update"] == "lead_note_form")) {
 $note = date("m/d/y H:i:s")." - ".$_SESSION['username']. '\n' . $note. '\n'; 
 $updateSQL = sprintf ("UPDATE Leads SET Notes = CONCAT_WS('\n', Notes, %s) WHERE Id=%d",
    GetSQLValueString($_POST['note'], "text"),
    GetSQLValueString($_POST['Id'], "int"));

  mysql_select_db($database_cms, $cms);
  $Result1 = mysql_query($updateSQL, $cms) or die(mysql_error());

  $updateGoTo = "test6.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_Recordset1 = "-1";
if (isset($_GET['Id'])) {
  $colname_Recordset1 = $_GET['Id'];
}
mysql_select_db($database_cms, $cms);
$query_Recordset1 = sprintf("SELECT Id, First_Name, Last_Name, Notes FROM Leads WHERE Id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $cms) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script language="JavaScript" src="jquery.js" type="text/javascript"></script>

<script>
function clickSubmit() {
    $("form").submit();
}
</script>

</head>

<body>

<table><tr><td>

<div id="lead_box">
<form action="<?php echo $editFormAction; ?>" method="POST" name="lead_note_form" id="lead_note_form" target="_top">
<input type="hidden" name="Id" id="Id" value="<?php echo $row_Recordset1['Id']; ?>" />
<table width="100%" border="0" cellpadding="0" cellspacing="5">
  <tr>
    <td colspan="2" bgcolor="#eeeeee"><p align="center" class="name"></p></td>
  </tr>
  <tr>
    <td><textarea rows="15" style="width: 99%" readonly><?php echo $row_Recordset1['Notes']; ?></textarea></td>
  </tr>
  <tr>
    <td valign="top"><p class="title">Add Note:</p></td>
  <tr>
    <td>
        <textarea name="note" id="note" style="width: 99%" rows="5"></textarea>
    </td>
  </tr>
</table>
<input type="hidden" name="MM_update" value="lead_note_form" />
</form>
</div><!-- and of lead box -->
</td></tr>
<tr><td>
<div align="right">
<input  type="submit" name="save" id="save" value="Save" onClick="clickSubmit()"/>
<input type="button" name="cancel" id="cancel" value="Cancel" onClick="window.parent.hidePopWin()"/>
</div>
</td></tr></table>



</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

on display page add function nl2br as shown here

<td><textarea rows="15" style="width: 99%" readonly><?php echo nl2br($row_Recordset1['Notes']); ?></textarea></td>

You should also change way you update note, new line must be between old note and new note

CONCAT_WS( Notes,'\r\n\r\n', %s)

ahhhh, it's still not working!!!! When I open the submodal box to retrieve the notes, i get </br> tags in between the notes..... not sure whats going on..... I put in the notes like you suggested...did I do it correctly? Here is the code..

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "lead_note_form")) {

$updateSQL = sprintf ("UPDATE Leads SET Notes = CONCAT_WS(Notes,'\r\n\r\n', %s) WHERE Id=%d",
GetSQLValueString($_POST, "text"),
GetSQLValueString($_POST, "int"));

This is the output of the notes...

<br />
<br />
<br />
<br />
great!<br />
Its awesome, really looking forward to it!<br />
This is fantastic, its finally working!<br />
whats up<br />
hello!<br />

it should not show <br/> is it part of your note

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.