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

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);
?>
LVL 1
edvinsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Frosty555Commented:
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
edvinsonAuthor Commented:
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
edvinsonAuthor Commented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Frosty555Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jason C. LevineNo oneCommented:
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
edvinsonAuthor Commented:
YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thank you again. That was the trick. You guys (& gals) are so amazing and this site is soooooooooooo worth the investment!!
0
Frosty555Commented:
Thanks for the extra explaination Jason. I knew what I meant but it needed some extra discussion ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.