[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Another easy one I'd guess. Can't get WYSIWYG to submit corrections to DB

Posted on 2008-01-30
7
Medium Priority
?
212 Views
Last Modified: 2013-12-12
Here's the code for www.plugasong.com/admin/index.php, but I can't figure out why (using Dreamweavers Update Server Behavior) it won't submit the changes to the database.

PLEASE HELP!!

<?php require_once('../Connections/PlugASong.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_update"])) && ($_POST["MM_update"] == "mainbody1")) {
  $updateSQL = sprintf("UPDATE textfields SET bodytext1=%s WHERE ID=%s",
                       GetSQLValueString($_POST['content'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));

  mysql_select_db($database_PlugASong, $PlugASong);
  $Result1 = mysql_query($updateSQL, $PlugASong) or die(mysql_error());

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

mysql_select_db($database_PlugASong, $PlugASong);
$query_Recordset1 = "SELECT * FROM textfields";
$Recordset1 = mysql_query($query_Recordset1, $PlugASong) 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=iso-8859-1" />
<title>Update Page</title>
<script language="javascript" type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
      mode : "textareas",
      theme : "advanced",
      plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu",
      theme_advanced_buttons1_add_before : "save,separator",
      theme_advanced_buttons1_add : "fontselect,fontsizeselect",
      theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
      theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
      theme_advanced_buttons3_add_before : "tablecontrols,separator",
      theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print",
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      theme_advanced_statusbar_location : "bottom",
      plugin_insertdate_dateFormat : "%Y-%m-%d",
      plugin_insertdate_timeFormat : "%H:%M:%S",
      extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
      external_link_list_url : "example_data/example_link_list.js",
      external_image_list_url : "example_data/example_image_list.js",
      flash_external_list_url : "example_data/example_flash_list.js"
});


</script>

<style type="text/css">
<!--
.editform {
      position: absolute;
}
-->
</style>
</head>

<body>

<div><form action="<?php echo $editFormAction; ?>" method="POST" name="mainbody1" id="mainbody1">
  <p>
    <textarea name="content" cols="50" rows="15"><?php echo $row_Recordset1['bodytext1']; ?></textarea>
    </p>
  <p>
    <input name="submit" type="submit" value="Save" />
    <input name="ID" type="hidden" id="ID" />
</p>
  <input type="hidden" name="MM_update" value="mainbody1">
</form></div>

<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
0
Comment
Question by:edvinson
  • 3
  • 3
7 Comments
 
LVL 31

Expert Comment

by:Frosty555
ID: 20784180
I'm gonna take a stab here. The UPDATE statement updates the record who's ID matches the posted "ID" field from your form.

This field in your form is a hidden field, your code for it is:
<input name="ID" type="hidden" id="ID" />

But it never hets a value. It's blank. So no records ever match. Where's the ID coming from on the page? Is it a page parameter? If so you can change it to something like this:

<input name="ID" type="hidden" id="ID" value="<?php echo $_GET["id"]; ?>" />

If you are using an "id" page parameter, your select statement to populate the form should change as well to reflect that.
0
 
LVL 1

Author Comment

by:edvinson
ID: 20784205
hmmm I pasted your code in to replace and it didn't seem to change anything.

There is only one item in the database, two fields one called ID and the other mainbody1

You can check the link and see it didn't work yet...sigh..
<?php require_once('../Connections/PlugASong.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_update"])) && ($_POST["MM_update"] == "mainbody1")) {
  $updateSQL = sprintf("UPDATE textfields SET bodytext1=%s WHERE ID=%s",
                       GetSQLValueString($_POST['content'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));
 
  mysql_select_db($database_PlugASong, $PlugASong);
  $Result1 = mysql_query($updateSQL, $PlugASong) or die(mysql_error());
 
  $updateGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
 
mysql_select_db($database_PlugASong, $PlugASong);
$query_Recordset1 = "SELECT * FROM textfields";
$Recordset1 = mysql_query($query_Recordset1, $PlugASong) 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=iso-8859-1" />
<title>Update Page</title>
<script language="javascript" type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu",
	theme_advanced_buttons1_add_before : "save,separator",
	theme_advanced_buttons1_add : "fontselect,fontsizeselect",
	theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
	theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
	theme_advanced_buttons3_add_before : "tablecontrols,separator",
	theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	plugin_insertdate_dateFormat : "%Y-%m-%d",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
	external_link_list_url : "example_data/example_link_list.js",
	external_image_list_url : "example_data/example_image_list.js",
	flash_external_list_url : "example_data/example_flash_list.js"
});
 
 
</script>
 
<style type="text/css">
<!--
.editform {
	position: absolute;
}
-->
</style>
</head>
 
<body>
 
<div><form action="<?php echo $editFormAction; ?>" method="POST" name="mainbody1" id="mainbody1">
  <p>
    <textarea name="content" cols="50" rows="15"><?php echo $row_Recordset1['bodytext1']; ?></textarea>
    </p>
  <p>
    <input name="submit" type="submit" value="Save" />
    <input name="ID" type="hidden" id="ID" value="<?php echo $_GET["id"]; ?>" />
 
</p>
  <input type="hidden" name="MM_update" value="mainbody1">
</form></div>
 
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Open in new window

0
 
LVL 1

Author Comment

by:edvinson
ID: 20784232
Here's the latest code I've tried:
<?php require_once('../Connections/PlugASong.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_update"])) && ($_POST["MM_update"] == "mainbody1")) {
  $updateSQL = sprintf("UPDATE textfields SET bodytext1=%s WHERE ID=%s",
                       GetSQLValueString($_POST['bodytext1'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));
 
  mysql_select_db($database_PlugASong, $PlugASong);
  $Result1 = mysql_query($updateSQL, $PlugASong) or die(mysql_error());
 
  $updateGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
 
mysql_select_db($database_PlugASong, $PlugASong);
$query_Recordset1 = "SELECT * FROM textfields";
$Recordset1 = mysql_query($query_Recordset1, $PlugASong) 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=iso-8859-1" />
<title>Update Page</title>
<script language="javascript" type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu",
	theme_advanced_buttons1_add_before : "save,separator",
	theme_advanced_buttons1_add : "fontselect,fontsizeselect",
	theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
	theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
	theme_advanced_buttons3_add_before : "tablecontrols,separator",
	theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	plugin_insertdate_dateFormat : "%Y-%m-%d",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
	external_link_list_url : "example_data/example_link_list.js",
	external_image_list_url : "example_data/example_image_list.js",
	flash_external_list_url : "example_data/example_flash_list.js"
});
 
 
</script>
 
<style type="text/css">
<!--
.editform {
	position: absolute;
}
-->
</style>
</head>
 
<body>
 
<div><form action="<?php echo $editFormAction; ?>" method="POST" name="mainbody1" id="mainbody1">
  <p>
    <textarea name="bodytext1" cols="50" rows="15" id="bodytext1"><?php echo $row_Recordset1['bodytext1']; ?></textarea>
    </p>
  <p>
    <input name="submit" type="submit" value="Save" />
    <input name="ID" type="hidden" id="ID" />
</p>
  
  <input type="hidden" name="MM_update" value="mainbody1">
</form></div>
 
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Open in new window

0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 31

Accepted Solution

by:
Frosty555 earned 500 total points
ID: 20784571
You will also need to access your page via something like

mypage.php?id=5

where 5 is the id of the record you want to edit.
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
ID: 20784781
Frosty is right on.   Let me see if I can explain it in simpler terms but make sure you give him/her the points...

Your SQL is this:

$query_Recordset1 = "SELECT * FROM textfields";

so that will pull ALL records from table textfields.  You are trying to edit ONE record, so you need to change the recordset so it returns only the one record you want edited.

You do this the same way we did it yesterday in this question and as Frosty says:

http://www.experts-exchange.com/Web_Development/Software/Macromedia_Dreamweaver/Q_23121384.html

You need to pass the id number of the record through the URL and then set the Filter section of the recordset wizard so that it uses the value to limit the recordset.  Your URL should be like this:

http://www.plugasong.com/admin/index.php?id=5 (or whatever ID number you want to edit)

Now that you have done that, you need to also make sure the ID exists in the form so the Update behavior knows which record to update.

You have the following in your HTML:

<input name="ID" type="hidden" id="ID" />

As Frosty says, there is no VALUE here.  So the Update Behavior will not do anything.  Change it to:

<input name="ID" type="hidden" id="ID" value="<?php echo $row_Recordset1['ID']; "/> (Change ID to match the column name in the SQL table)

or select the hidden field and use the lightning bolt icon next to the value box in the Properties Panel to bind the correct column to the hidden field.
0
 
LVL 1

Author Closing Comment

by:edvinson
ID: 31426659
YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thank you again. That was the trick. You guys (& gals) are so amazing and this site is soooooooooooo worth the investment!!
0
 
LVL 31

Expert Comment

by:Frosty555
ID: 20791473
Thanks for the extra explaination Jason. I knew what I meant but it needed some extra discussion ;)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question