单击“提交”按钮时,我的更新页面未编辑数据库中的数据。我不知道哪里出错了。我检查了与数据库的连接及其工作正常,因为它正在检索以前的数据。
这是我的更新页面编码
<b>Notice</b>: Undefined index: user_message in <b>/home4/gregre/public_html/example.com/insert_announcements.php</b> on line <b>9</b><br />
答案 0 :(得分:0)
这是我的编辑代码。上一页应链接到此页面
<?php
$mysqlconnection= mysql_connect ("localhost", "root","") or die (mysql_error());
mysql_select_db ("smpi");
?>
<?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 maklumat_pencetak SET Jabatan=%s, Work_Group=%s, Kategori_Infra=%s, Nama_Pengguna=%s, Jawatan=%s, Gred_Jawatan=%s, Tahun_Perolehan=%s, No_Aset=%s, No_Siri=%s, Jenis_OS_Pc=%s, Jenama=%s, Model=%s, Harga_Infra=%s, Kategori_Printer=%s, Jenis_Printer=%s, Status_Infra=%s, Status_Penyelenggaran=%s, Syarikat_Penyelenggaran=%s WHERE Agensi=%s",
GetSQLValueString($_POST['Jabatan'], "text"),
GetSQLValueString($_POST['Work_Group'], "text"),
GetSQLValueString($_POST['Kategori_Infra'], "text"),
GetSQLValueString($_POST['Nama_Pengguna'], "text"),
GetSQLValueString($_POST['Jawatan'], "text"),
GetSQLValueString($_POST['Gred_Jawatan'], "text"),
GetSQLValueString($_POST['Tahun_Perolehan'], "int"),
GetSQLValueString($_POST['No_Aset'], "text"),
GetSQLValueString($_POST['No_Siri'], "text"),
GetSQLValueString($_POST['Jenis_OS_PC'], "text"),
GetSQLValueString($_POST['Jenama'], "text"),
GetSQLValueString($_POST['Model'], "text"),
GetSQLValueString($_POST['Harga_Infra'], "int"),
GetSQLValueString($_POST['Kategori_Printer'], "text"),
GetSQLValueString($_POST['Jenis_Printer'], "text"),
GetSQLValueString($_POST['Status_Infra'], "text"),
GetSQLValueString($_POST['Status_Penyelenggaran'], "text"),
GetSQLValueString($_POST['Syarikat_Penyelenggaran'], "text"),
GetSQLValueString($_POST['No_Siri'], "text"));
mysql_select_db($database_smpiconnection, $smpiconnection);
$Result1 = mysql_query($updateSQL, $smpiconnection) or die(mysql_error());
$updateGoTo = "printerupdatepage.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db( "smpi");
$query_printer = "SELECT ALL FROM maklumat_pencetak";
$printer = mysql_query($query_printer, $mysqlconnection) or die(mysql_error());
$row_printer = mysql_fetch_assoc($printer);
$totalRows_printer = mysql_num_rows($printer);
?>
<!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>
<style type="text/css">
body {
background-image: url(wooden.jpg);
}
body,td,th {
color: #FFF;
}
</style>
</head>
<body>
<center>
<p><img src="bannercrop.png" alt="crop" width="1180" height="324" align="middle" longdesc="bannercrop.png" /></p>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p>
<label for="Agensi">Agen<?php echo $row_printer['Agensi']; ?>si</label>
:
<input name="Agensi" type="text" id="Agensi" value="<?php echo $row_printer['Agensi']; ?>" />
</p>
<p>
<label for="Jabatan">Jabat<?php echo $row_printer['Jabatan']; ?>an</label>
:
<input name="Jabatan" type="text" id="Jabatan" value="<?php echo $row_printer['Jabatan']; ?>" />
</p>
<p>
<label for="Work_Group">Work Gr<?php echo $row_printer['Work_Group']; ?>oup</label>
:
<input name="Work_Group" type="text" id="Work_Group" value="<?php echo $row_printer['Work_Group']; ?>" />
</p>
<p>
<label for="Kategori_Infra">Kategori Infra<?php echo $row_printer['Kategori_Infra']; ?>:</label>
<input name="Kategori_Infra" type="text" id="Kategori_Infra" value="<?php echo $row_printer['Kategori_Infra']; ?>" />
</p>
<p>
<label for="Nama_Pengguna">Nama_Pengguna<?php echo $row_printer['Nama_Pengguna']; ?>:</label>
<input name="Nama_Pengguna" type="text" id="Nama_Pengguna" value="<?php echo $row_printer['Nama_Pengguna']; ?>" />
</p>
<p>
<label for="Jawatan">Jawatan<?php echo $row_printer['Jawatan']; ?> :</label>
<input name="Jawatan" type="text" id="Jawatan" value="<?php echo $row_printer['Jawatan']; ?>" />
</p>
<p>
<label for="Gred_Jawatan">Gred Jawatan<?php echo $row_printer['Gred_Jawatan']; ?> :</label>
<input name="Gred_Jawatan" type="text" id="Gred_Jawatan" value="<?php echo $row_printer['Gred_Jawatan']; ?>" />
</p>
<p>
<label for="Tahun_Perolehan">Tahun Perolehan<?php echo $row_printer['Tahun_Perolehan']; ?>:</label>
<input name="Tahun_Perolehan" type="text" id="Tahun_Perolehan" value="<?php echo $row_printer['Tahun_Perolehan']; ?>" />
</p>
<p>
<label for="No_Aset">No Ase<?php echo $row_printer['No_Aset']; ?>t:</label>
<input name="No_Aset" type="text" id="No_Aset" value="<?php echo $row_printer['No_Aset']; ?>" />
</p>
<p>
<label for="No_Siri">No Siri<?php echo $row_printer['No_Siri']; ?>:</label>
<input name="No_Siri" type="text" id="No_Siri" value="<?php echo $row_printer['No_Siri']; ?>" />
</p>
<p>
<label for="Jenis_OS_PC">Jenis OS PC <?php echo $row_printer['Jenis_OS_Pc']; ?>:</label>
<input name="Jenis_OS_PC" type="text" id="Jenis_OS_PC" value="<?php echo $row_printer['Jenis_OS_Pc']; ?>" />
</p>
<p>
<label for="Jenama">Jenama<?php echo $row_printer['Jenama']; ?>:</label>
<input name="Jenama" type="text" id="Jenama" value="<?php echo $row_printer['Jenama']; ?>" />
</p>
<p>
<label for="Model">Model<?php echo $row_printer['Model']; ?> :</label>
<input name="Model" type="text" id="Model" value="<?php echo $row_printer['Model']; ?>" />
</p>
<p>
<label for="Harga_Infra">Harga Infra<?php echo $row_printer['Harga_Infra']; ?> :</label>
<input name="Harga_Infra" type="text" id="Harga_Infra" value="<?php echo $row_printer['Harga_Infra']; ?>" />
</p>
<p>
<label for="Kategori_Printer">Kategori Printer</label>
<?php echo $row_printer['Kategori_Printer']; ?>
:
<input name="Kategori_Printer" type="text" id="Kategori_Printer" value="<?php echo $row_printer['Kategori_Printer']; ?>" />
</p>
<p>
<label for="Jenis_Printer">Jenis Printer <?php echo $row_printer['Jenis_Printer']; ?>:</label>
<input name="Jenis_Printer" type="text" id="Jenis_Printer" value="<?php echo $row_printer['Jenis_Printer']; ?>" />
</p>
<p>
<label for="Status_Infra">Status Infra <?php echo $row_printer['Status_Infra']; ?>:</label>
<input name="Status_Infra" type="text" id="Status_Infra" value="<?php echo $row_printer['Status_Infra']; ?>" />
</p>
<p>
<label for="Status_Penyelenggaran">Status Penyelenggaran<?php echo $row_printer['Status_Penyelenggaran']; ?>:</label>
<input name="Status_Penyelenggaran" type="text" id="Status_Penyelenggaran" value="<?php echo $row_printer['Status_Penyelenggaran']; ?>" />
</p>
<p>
<label for="Syarikat_Penyelenggaran">Syarikat Penyelenggaran<?php echo $row_printer['Syarikat_Penyelenggaran']; ?>:</label>
<input name="Syarikat_Penyelenggaran" type="text" id="Syarikat_Penyelenggaran" value="<?php echo $row_printer['Syarikat_Penyelenggaran']; ?>" />
</p>
<p>
<input type="submit" name="update" id="submit" value="UPDATE!" />
</p>
<input type="hidden" name="MM_update" value="form1" />
</form>
</center>
</body>
</html>
<?php
mysql_free_result($printer);
?>
&#13;