0

http://imageshack.us/photo/my-images/221/mysystem.jpg/

任何人都可以帮助我,我现在卡在第一列,即 Total Pending Column,我无法在前端页面更改“200”的数据,我只能在 phpmyadmin 的后端页面手动编辑它,这对我来说很难用户在前端更改数据,但是让我感到困惑,为什么另一列可以在前端进行编辑?只是无法编辑 Total Pending 列,当我单击更新按钮时,除第一列之外的其他列都更新了。

请帮我..

特此更新 PHP 编码

$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 sr1 SET appt_today=%s, partial_complete=%s, full_complete=%s, return_technical=%s, return_customer=%s, return_cancel=%s, cancel=%s, reappt=%s, focus=%s WHERE total_pending=%s",
                       GetSQLValueString($_POST['appt_today'], "int"),
                       GetSQLValueString($_POST['partial_complete'], "int"),
                       GetSQLValueString($_POST['full_complete'], "int"),
                       GetSQLValueString($_POST['return_technical'], "int"),
                       GetSQLValueString($_POST['return_customer'], "int"),
                       GetSQLValueString($_POST['return_cancel'], "int"),
                       GetSQLValueString($_POST['cancel'], "int"),
                       GetSQLValueString($_POST['reappt'], "int"),
                       GetSQLValueString($_POST['focus'], "int"),
                       GetSQLValueString($_POST['total_pending'], "int"));

  mysql_select_db($database_pods, $pods);
  $Result1 = mysql_query($updateSQL, $pods) or die(mysql_error());

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

mysql_select_db($database_pods, $pods);
$query_sr1 = "SELECT * FROM sr1";
$sr1 = mysql_query($query_sr1, $pods) or die(mysql_error());
$row_sr1 = mysql_fetch_assoc($sr1);
$totalRows_sr1 = mysql_num_rows($sr1);
?>

这是我的输入数据编码,我上面说的是“200”,但不能更新。

<input name="total_pending" type="text" class="style6" onKeyPress="return checkIt(event)" value="<?php echo $row_sr1['total_pending']; ?>" size="3" maxlength="3" />
4

1 回答 1

1

您的 SQL 查询不会更新任何名为total_pending

UPDATE
  sr1
SET
  appt_today=%s,
  partial_complete=%s,
  full_complete=%s,
  return_technical=%s,
  return_customer=%s,
  return_cancel=%s,
  cancel=%s,
  reappt=%s,
  focus=%s
WHERE
  total_pending=%s

您用于total_pending查找要更新的记录,但实际上并未更新该/那些记录中的该值。

请记住,为了更新您用于查找记录的同一字段,您需要将该参数包含两次并使用两个不同的值。一个是它应该更新的新值,一个是它用来查找记录的现有值。

例如:

UPDATE
  sr1
SET
  appt_today=%s,
  partial_complete=%s,
  full_complete=%s,
  return_technical=%s,
  return_customer=%s,
  return_cancel=%s,
  cancel=%s,
  reappt=%s,
  focus=%s,
  total_pending=%s -- update this field as well
WHERE
  total_pending=%s

编辑:为了更清楚地为您说明,您要做的第一件事是在表单中添加另一个字段以跟踪单独的total_pending值。这是因为您需要其中两个用于更新,一个代表原始值(用于WHERE子句),一个代表新值。因此,您需要添加如下内容:

<input name="total_pending_original" type="hidden" value="<?php echo $row_sr1['total_pending']; ?>" />

然后,使用我上面给你的更新查询,你还需要添加一个新参数。所以总的查询/参数代码应该是这样的:

$updateSQL = sprintf("UPDATE sr1 SET appt_today=%s, partial_complete=%s, full_complete=%s, return_technical=%s, return_customer=%s, return_cancel=%s, cancel=%s, reappt=%s, focus=%s, total_pending=%s WHERE total_pending=%s",
                   GetSQLValueString($_POST['appt_today'], "int"),
                   GetSQLValueString($_POST['partial_complete'], "int"),
                   GetSQLValueString($_POST['full_complete'], "int"),
                   GetSQLValueString($_POST['return_technical'], "int"),
                   GetSQLValueString($_POST['return_customer'], "int"),
                   GetSQLValueString($_POST['return_cancel'], "int"),
                   GetSQLValueString($_POST['cancel'], "int"),
                   GetSQLValueString($_POST['reappt'], "int"),
                   GetSQLValueString($_POST['focus'], "int"),
                   GetSQLValueString($_POST['total_pending'], "int"),
                   GetSQLValueString($_POST['total_pending_original'], "int"));

此外,您应该注意的一件事是您不应该再成为 mysql_* 函数。PHP 正在弃用它们。看看这里指示的大红色框。

于 2012-07-27T13:08:17.083 回答