Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating from a CKEditor textarea 1

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
Hi.
With the help of my old Dreamweaver2004 I'm failing to update text to MYSQL dbase from a CKEditor textarea.
It's not something i've done before and with the code I got I find that when I submit a text-change the textarea next displays the original text. However the change appears in the textarea if I click submit again. In other words the textarea and the dbase entry just swap places!
I've tried changing the order of various elements of code, but have not been able to discover how to get the textarea to display the changed text straight away. The head code is, following the Access Restriction Code:
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;
}

$writer = $_SESSION['MM_Username'];  //Variable set to select correct Record (below)

mysql_select_db($database_tormented3, $tormented3);
$query_rstAut = "SELECT firstname FROM authors WHERE username = '$writer'";
$rstAut = mysql_query($query_rstAut, $tormented3) or die(mysql_error());
$row_rstAut = mysql_fetch_assoc($rstAut);
$totalRows_rstAut = mysql_num_rows($rstAut);

$originalString = $row_rstAut['firstname'];  // These 2 lines replace the Capital letter of "firstname" and replace it with a lowercase letter.
$lowerCase = strtolower($originalString);
$user = auth_ . $lowerCase ; //  To set a variable that will link the user to their database table.

$colname_rstTex = "1";
if (isset($_GET['read'])) {
  $colname_rstTex = (get_magic_quotes_gpc()) ? $_GET['read'] : addslashes($_GET['read']);
}

mysql_select_db($database_tormented3, $tormented3);
$query_rstTex =  sprintf("SELECT * FROM $user WHERE title = '%s'", $colname_rstTex); 
$rstTex = mysql_query($query_rstTex, $tormented3) or die(mysql_error());
$row_rstTex = mysql_fetch_assoc($rstTex);
$totalRows_rstTex = mysql_num_rows($rstTex); 

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE $user SET text=%s WHERE title=%s",
                       GetSQLValueString($_POST['editor1'], "text"),
                       GetSQLValueString($_POST['title'], "text"));

  mysql_select_db($database_tormented3, $tormented3);
  $Result1 = mysql_query($updateSQL, $tormented3) or die(mysql_error());
}

The form code is:
HTML:
<form action="<?php echo $editFormAction; ?>" name="form1" method="POST">
          <input name="title" type="text" value="<?php echo $row_rstTex['title']; ?>"  size="30" maxlength="30">		
          <textarea name="editor1" id="editor1" rows="50" cols="80" ><?php echo $row_rstTex['text'] ;?>
            </textarea>
            <script>
                // Replace the <textarea id="editor1"> with a CKEditor
                // instance, using default configuration.
                CKEDITOR.replace( 'editor1' );
            </script>
		<input type="submit" name="Submit" value="Submit">
<input type="hidden" name="MM_update" value="form1">
        </form>
Can you help me out of this little dilemma, please?
 
Move the update logic before the select logic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top