Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Help! Can't get Update page to accept changes because "item is already registered"

LEGEND ,
Jan 18, 2008 Jan 18, 2008

Copy link to clipboard

Copied

Hi,

I have created an update page from my insert page similar to chapter 9
in PHP DW8, but I can't get the update to work because it always says
"item is already registered". I have been looking at the code for two
days now and comparing it to the similar author_update.php from the
book, but I just can't find the problem. I'm hoping that someone here
with more knowledge and a fresh set of eyes can spot the problem. Here
is the code:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$var1_checkModnum = "default";
if (isset($_POST['mod_num'])) {
$var1_checkModnum = $_POST['mod_num'];
}
mysql_select_db($database_belleadmin, $belleadmin);
$query_checkModnum = sprintf("SELECT * FROM products WHERE products.mod_num = %s", GetSQLValueString($var1_checkModnum, "text"));
$checkModnum = mysql_query($query_checkModnum, $belleadmin) or die(mysql_error());
$row_checkModnum = mysql_fetch_assoc($checkModnum);
$totalRows_checkModnum = mysql_num_rows($checkModnum);

mysql_select_db($database_belleadmin, $belleadmin);
$query_divList = "SELECT * FROM divisions ORDER BY div_name ASC";
$divList = mysql_query($query_divList, $belleadmin) or die(mysql_error());
$row_divList = mysql_fetch_assoc($divList);
$totalRows_divList = mysql_num_rows($divList);

mysql_select_db($database_belleadmin, $belleadmin);
$query_groupList = "SELECT * FROM `group` ORDER BY group_name ASC";
$groupList = mysql_query($query_groupList, $belleadmin) or die(mysql_error());
$row_groupList = mysql_fetch_assoc($groupList);
$totalRows_groupList = mysql_num_rows($groupList);

mysql_select_db($database_belleadmin, $belleadmin);
$query_segList = "SELECT * FROM segment ORDER BY seg_name ASC";
$segList = mysql_query($query_segList, $belleadmin) or die(mysql_error());
$row_segList = mysql_fetch_assoc($segList);
$totalRows_segList = mysql_num_rows($segList);

mysql_select_db($database_belleadmin, $belleadmin);
$query_catList = "SELECT * FROM category ORDER BY cat_name ASC";
$catList = mysql_query($query_catList, $belleadmin) or die(mysql_error());
$row_catList = mysql_fetch_assoc($catList);
$totalRows_catList = mysql_num_rows($catList);

$colname_getProduct = "-1";
if (isset($_GET['prod_id'])) {
$colname_getProduct = $_GET['prod_id'];
}
mysql_select_db($database_belleadmin, $belleadmin);
$query_getProduct = sprintf("SELECT * FROM products WHERE prod_id = %s", GetSQLValueString($colname_getProduct, "int"));
$getProduct = mysql_query($query_getProduct, $belleadmin) or die(mysql_error());
$row_getProduct = mysql_fetch_assoc($getProduct);
$totalRows_getProduct = mysql_num_rows($getProduct);


// assume that no match has been found
$alreadyRegistered = false;

// check whether recordset found any matches
if ($totalRows_checkModnum > 0) {
// if found, reset $alreadyRegistered
$alreadyRegistered = true;
}
else {
// go ahead with insert record behavior
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "updateProduct")) {
$updateSQL = sprintf("UPDATE products SET mod_num=%s, div_id=%s, group_id=%s, seg_id=%s, cat_id=%s, title=%s, `desc`=%s, thick=%s, width=%s, height=%s, project=%s, image=%s WHERE prod_id=%s",
GetSQLValueString($_POST['mod_num'], "text"),
GetSQLValueString($_POST['div_id'], "int"),
GetSQLValueString($_POST['group_id'], "int"),
GetSQLValueString($_POST['seg_id'], "int"),
GetSQLValueString($_POST['cat_id'], "int"),
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['desc'], "text"),
GetSQLValueString($_POST['thick'], "double"),
GetSQLValueString($_POST['width'], "double"),
GetSQLValueString($_POST['height'], "double"),
GetSQLValueString($_POST['project'], "double"),
GetSQLValueString($_POST['image'], "text"),
GetSQLValueString($_POST['prod_id'], "int"));

mysql_select_db($database_belleadmin, $belleadmin);
$Result1 = mysql_query($updateSQL, $belleadmin) or die(mysql_error());

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

Any help would be greatly appreciated.
TOPICS
Server side applications

Views

195
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2008 Jan 18, 2008

Copy link to clipboard

Copied

LATEST
Brett wrote:
> I have created an update page from my insert page similar to chapter 9
> in PHP DW8, but I can't get the update to work because it always says
> "item is already registered".

I have already answered this in the friends of ED forum.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines