Skip to main content
Participating Frequently
October 13, 2009
Question

Trying to use the Update Record Form...unsuccessfully. Help!

  • October 13, 2009
  • 4 replies
  • 1488 views

I have successfully created a Login page that will carry a session variable to the User Update Page.  The problem is that the Dynamic Data in the form fields aren't pulling up the record from the MySQL table.  Then if I type anything into the fields and try to perform an update just to test it, it goes to a black page with the error message "Incorrect table name." 

I would appreciate any help with this.  I'm using DW CS4, MySQL & PHP.

Thanks!

This topic has been closed for replies.

4 replies

Lon_Winters
Inspiring
October 14, 2009

Here are the basic steps, perhaps you can check these against what you have.

1.  Created a recordet based on the User ID session variable - test the recodset in the behavior panel to make sure it's returning data

2. Bind the database fields to the form fields.

3.  Apply the update behavior, select the recordset you created n step one and specify a redirect page.

If you've done all these and it's not working, then please post your code and or a link to the page in question.

scmeekerAuthor
Participating Frequently
October 14, 2009

Hi Lon...thanks for your help again. 


Okay, when I first made the Recordset in the "simple" mode, it tested fine.  Then after I hit "okay", it had a red exclamation point next to it.  Upon clicking it again and hitting the "test" button it gave me the following error:  "totalRows is an invalid variable name; it does not appear in the SQL.  Missing type for variable:totalRows."


When you stated to "bind the database fields to the form fields," are you talking about inserting the Dynamic Data...the "Init val" with the lightening bolt?  If so, I did do that too.


Also, the 3rd thing, "

Apply the update behavior, select the recordset you created n step one and specify a redirect page." 

When I apply the update behavior, do I click on the Submit button to select that or the form it is in?  When I went to reclick on the behavior,
I didn't see a place to select the recordset.  No problem with the "redirect page."

Also when I now click on the update behavior, it gives me the following error:  "While executing inspectServerBehavior in UpdateRecord.htm
a JavaScript error occured."

Eeeeyiieh!   Thanks for your help.  I'm also going to post the code below:

<?php require_once('Connections/sgallery.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"] == "form1")) {
  $updateSQL = sprintf("UPDATE ``artist id`` SET `First Name`=%s, `Last Name`=%s, Street=%s, City=%s, Zip=%s, email=%s, username=%s, password=%s WHERE `Artist ID`=%s",
                       GetSQLValueString($_POST['First Name'], "text"),
                       GetSQLValueString($_POST['Last Name'], "text"),
                       GetSQLValueString($_POST['Street'], "text"),
                       GetSQLValueString($_POST['City'], "text"),
                       GetSQLValueString($_POST['Zip'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['hiddenField'], "int"));

  mysql_select_db($database_sgallery, $sgallery);
  $Result1 = mysql_query($updateSQL, $sgallery) or die(mysql_error());
}

$colname_Recordset1 = "-1";
if (isset($_POST['Artist ID'])) {
  $colname_Recordset1 = $_POST['Artist ID'];
}
mysql_select_db($database_sgallery, $sgallery);
$query_Recordset1 = sprintf("SELECT * FROM `artist id` WHERE `Artist ID` = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $sgallery) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = "-1";
if (isset($_SESSION['Artist ID'])) {
  $totalRows_Recordset1 = $_SESSION['Artist ID'];
}
$colname_Recordset1 = "-1";
if (isset()) {
  $colname_Recordset1 = ;
}
mysql_select_db($database_sgallery, $sgallery);
$query_Recordset1 = sprintf("SELECT * FROM `artist id` WHERE `Artist ID` = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $sgallery) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);$colname_Recordset1 = "-1";
if (isset($_POST['Artist ID'])) {
  $colname_Recordset1 = $_POST['Artist ID'];
}
mysql_select_db($database_sgallery, $sgallery);
$query_Recordset1 = sprintf("SELECT * FROM `artist id` WHERE `Artist ID` = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $sgallery) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset1 = "-1";
if (isset($_SESSION['Artist ID'])) {
  $colname_Recordset1 = $_SESSION['Artist ID'];
}
mysql_select_db($database_sgallery, $sgallery);
$query_Recordset1 = sprintf("SELECT * FROM `artist id` WHERE `Artist ID` = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $sgallery) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($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" />
<title>S Gallery Online</title>
<link href="sgallery.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
     background-image: url(BASICartistform.gif);
     background-repeat: no-repeat;
     margin-bottom: 1000px;
     margin-top: 0px;
     margin-left: 0px;
     margin-right: 0px;
     background-color: #000000;
}
-->
</style>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div class="header">
  <div class="logo"></div>
  <div class="headermenu">
    <ul id="MenuBar1" class="MenuBarHorizontal">
      <li>
        <div align="center"><a href="index.php">Home</a> </div>
      </li>
      <li>
        <div align="center"><a href="onlineartgalleries.php" class="MenuBarItemSubmenu">Galleries</a>
            <ul>
                <li><a href="paintinggallery.php">Paintings</a>                </li>
                <li><a href="printmakingartgallery.php">Printmaking</a>                </li>
                <li><a href="sculptureartgallery.php">Sculpture</a>                </li>
              <li><a href="pastelartgallery.php">Pastels</a></li>
              <li><a href="photographyartgallery.php">Photography</a></li>
              <li><a href="mixedmediaartgallery.php">Mixed Media</a></li>
              <li><a href="digitalartgallery.php">Drawings</a>              </li>
              <li><a href="fiberartgallery.php">Fiber Art</a></li>
              <li><a href="jewelryartgallery.php">Jewelry</a></li>
              <li><a href="digitalartgallery.php">Digital Art</a></li>
            </ul>
        </div>
      </li>
      <li>
        <div align="center"><a href="joinonlineartgallery1.php">Join</a> </div>
      </li>
      <li>
        <div align="center"><a href="#">Blog</a></div>
      </li>
      <li>
        <div align="center"><a href="about.php">About</a></div>
      </li>
      <li>
        <div align="center"><a href="#">FAQ</a></div>
      </li>
      <li>
        <div align="center"><a href="contactus.php">Contact</a></div>
      </li>
      <li>
        <div align="center"><a href="memberlogin.php">LOGIN</a></div>
      </li>
    </ul>
  </div>
  <div class="maincontent">
    <div class="quicklinks"><span class="fontquicklinks">Art News</span><br />
      <span class="fontquicklinks">Competitions</span><br />
      <span class="fontquicklinks">Art Schools</span><br />
      <span class="fontquicklinks">Museums</span><br />
      <span class="fontquicklinks">Art Resources</span><br />
      <span class="fontquicklinks">Exhibitions</span><br />
      <span class="fontquicklinks">Paintings</span><br />
      <span class="fontquicklinks">Sculpture</span><br />
      <span class="fontquicklinks">Photography</span><br />
        <span class="fontquicklinks">Pastels</span><br />
        <span class="fontquicklinks">Mixed Media</span><br />
        <span class="fontquicklinks">Printmaking</span><br />
        <span class="fontquicklinks">Drawings</span><br />
        <span class="fontquicklinks">Fiber Art</span><br />
        <span class="fontquicklinks">Jewelry</span><br />
        <span class="fontquicklinks">Digital Art</span><br />
          <span class="fontquicklinks">Submit an Event</span><br />
    </div>
   
    <div class="imageupload">Information Update/Edit:<br />
      <br />
     
      <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
        <label>
          <input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_Recordset1['Artist ID']; ?>" />
          <br />
          First Name:
          <input name="First Name" type="text" id="First Name" value="<?php echo $row_Recordset1['First Name']; ?>" />
        </label>
        <br />
        <label>Last Name:
          <input name="Last Name" type="text" id="Last Name" value="<?php echo $row_Recordset1['Last Name']; ?>" />
        </label>
        <br />
        <label>Street:        
          <input name="Street" type="text" id="Street" value="<?php echo $row_Recordset1['Street']; ?>" />
        </label>
        <br />
        <label>City:
          <input name="City" type="text" id="City" value="<?php echo $row_Recordset1['City']; ?>" />
        </label>
        <br />
        <label>Zip:
          <input name="Zip" type="text" id="Zip" value="<?php echo $row_Recordset1['Zip']; ?>" />
        </label>
        <br />
        <label>Email:
          <input name="email" type="text" id="email" value="<?php echo $row_Recordset1['email']; ?>" />
        </label>
        <br />
        <label>Username:
          <input name="username" type="text" id="username" value="<?php echo $row_Recordset1['username']; ?>" />
        </label>
        <br />
        <label>Password:
          <input name="password" type="password" id="password" value="<?php echo $row_Recordset1['password']; ?>" />
        </label>
        <br />
        <label>Update
          <input type="submit" name="update" id="update" value="Submit" />
        </label>
        <br />
        <br />
        <input type="hidden" name="MM_update" value="form1" />
      </form>
      <p> </p>
      <p> </p>
<p> </p>
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
    </div>
  </div>
  <div class="adssidebar"></div>
</div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
}



October 15, 2009

To assure the data displayed based on respective users, create a recordset from the table  by filter it using username -> Session Variable -> MM_Username. To view the data in form before update, click the textbox, you may see Dynamic button at properties panel. Click it and choose the recordset that u have just created and choose the data that u want to display.