私はdreamweaverを使用しており、ページに2つのフォームがあり、それぞれが同じmySQLデータベースに送信されますが、phpを使用して行が異なります。データをmySQLに送信するときに値が失われないようにするための「スティッキー」コードがあります。問題は、form2 を送信すると form1 の値が失われ、その逆も同様です。丸 2 日間、私は頭がおかしくなりました。前もって感謝します。
<?php require_once('Connections/pmpConn.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"] == "form2")) {
$updateSQL = sprintf("UPDATE readiness_one_day SET on_time=%s WHERE ready_primary=%s",
GetSQLValueString(isset($_POST['on_time2']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['ready_primary2'], "int"));
mysql_select_db($database_pmpConn, $pmpConn);
$Result1 = mysql_query($updateSQL, $pmpConn) or die(mysql_error());
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE readiness_one_day SET on_time=%s WHERE ready_primary=%s",
GetSQLValueString(isset($_POST['on_time1']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['ready_primary1'], "int"));
mysql_select_db($database_pmpConn, $pmpConn);
$Result1 = mysql_query($updateSQL, $pmpConn) or die(mysql_error());
}
?>
<!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>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p>
<input name="ready_primary1" type="text" id="ready_primary1" value="1" size="2" maxlength="2" readonly="readonly" />
</p>
<p>
<input name="on_time1" type="checkbox" id="on_time1" value="1"<?php if (isset($_POST['on_time1']) && ($_POST['on_time1'] == '1')) echo 'checked="checked" '; ?> /> <!code for sticky checkboxes>
<label for="on_time1">On Time</label>
</p>
<p>
<input type="submit" name="submit1" id="submit1" value="Update" />
</p>
<input type="hidden" name="MM_update" value="form1" />
</form>
<form id="form2" name="form2" method="POST" action="<?php echo $editFormAction; ?>" >
<p>
<input name="ready_primary2" type="text" id="ready_primary2" value="2" size="2" maxlength="2" readonly="readonly" />
</p>
<p>
<input name="on_time2" type="checkbox" id="on_time2" value="1" <?php if (isset($_POST['on_time2']) && ($_POST['on_time2'] == '1')) echo 'checked="checked" '; ?> /> <!code for sticky checkboxes>
<label for="on_time2">On Time</label>
</p>
<input type="submit" name="submit2" id="submit2" value="Update" />
<input type="hidden" name="MM_update" value="form2" />
</form>
</body>
</html>