พอเพิ่มข้อมูลแ้ล้วกดบันทึก จะรีไดเร็คหน้ามา1 หน้าแล้วก้อขึ้นคำนี้คะDuplicate entry '523535408' for key 1
โค๊ดคะ
<META http-equiv=Content-Type content="text/html; charset=windows-874">
<?php
$dbconn = mysql_connect('localhost', 'root', '');
$report_db = "report";
mysql_select_db($report_db);
mysql_query("SET NAMES 'tis620' ");
?>
<?php require_once('Connections/dbconn.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO personal (user_id, pass_id, p_pos, username) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['บุคคลากร'], "text"),
GetSQLValueString($_POST['รหัส'], "text"),
GetSQLValueString($_POST['manu1'], "text"),
GetSQLValueString($_POST['ชื่อ'], "text"));
mysql_select_db($database_dbconn, $dbconn);
$Result1 = mysql_query($insertSQL, $dbconn) or die(mysql_error());
$insertGoTo = "insert.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
// header(sprintf("Location:%s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO personal (user_id) VALUES (%s)",
GetSQLValueString($_POST['บุคคลากร'], "text"));
mysql_select_db($database_dbconn, $dbconn);
$Result1 = mysql_query($insertSQL, $dbconn) or die(mysql_error());
$insertGoTo = "insertok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO personal (username) VALUES (%s)",
GetSQLValueString($_POST['ชื่อ'], "text"));
mysql_select_db($database_dbconn, $dbconn);
$Result1 = mysql_query($insertSQL, $dbconn) or die(mysql_error());
$insertGoTo = "insertok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO personal (p_pos) VALUES (%s)",
GetSQLValueString($_POST['manu1'], "text"));
mysql_select_db($database_dbconn, $dbconn);
$Result1 = mysql_query($insertSQL, $dbconn) or die(mysql_error());
$insertGoTo = "insertok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO personal (pass_id) VALUES (%s)",
GetSQLValueString($_POST['รหัส'], "text"));
mysql_select_db($database_dbconn, $dbconn);
$Result1 = mysql_query($insertSQL, $dbconn) or die(mysql_error());
$insertGoTo = "insertok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_dbconn, $dbconn);
$query_rem = "SELECT * FROM personal ORDER BY user_id ASC";
$rem = mysql_query($query_rem, $dbconn) or die(mysql_error());
$row_rem = mysql_fetch_assoc($rem);
$totalRows_rem = mysql_num_rows($rem);
mysql_select_db($database_dbconn, $dbconn);
$query_rem_1 = "SELECT * FROM personal ORDER BY user_id ASC";
$rem_1 = mysql_query($query_rem_1, $dbconn) or die(mysql_error());
$row_rem_1 = mysql_fetch_assoc($rem_1);
$totalRows_rem_1 = mysql_num_rows($rem_1);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>ระบบรายงานการปฎิบัติงาน</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" target="_blank">
<table width="323" border="0" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">
<tr>
<td width="121"> รหัสพนักงาน</td>
<td width="192"><input name="บุคคลากร" type="text" id="บุคคลากร"></td>
</tr>
<tr>
<td>ชื่อผู้ใช้งาน</td>
<td><input name="ชื่อ" type="text" id="ชื่อ"></td>
</tr>
<tr>
<td>ตำแหน่ง</td>
<td><select name="manu1" id="manu1">
<option value="" <?php if (!(strcmp("", $row_rem['p_pos']))) {echo "SELECTED";} ?>>เลือก</option>
<option value="manager" <?php if (!(strcmp("manager", $row_rem['p_pos']))) {echo "SELECTED";} ?>>ผู้บริหาร</option>
<option value="admin" <?php if (!(strcmp("admin", $row_rem['p_pos']))) {echo "SELECTED";} ?>>ผู้ดูแลระบบ</option>
<option value="angineer" <?php if (!(strcmp("angineer", $row_rem['p_pos']))) {echo "SELECTED";} ?>>เจ้าหน้าที่</option>
</select></td>
</tr>
<tr><td>รหัสผ่าน</td> <td><input name="รหัส" type="password" id="รหัส"></td></tr>
<tr> <td colspan="2"><div align="center"><input name="Submit1" type="submit" id="Submit1" value="บันทึกข้อมูล">
</div></td> </tr>
</table>
<p> </p>
<p>
<input type="hidden" name="MM_insert" value="form1">
</p>
</form>
<form action="index2.php" method="post" enctype="multipart/form-data" name="form2" target="_blank">
<table width="774" border="0" align="center">
<tr bordercolor="#FFCCFF" bgcolor="#FFFFCC">
<td width="180"><div align="center">รหัสพนักงาน</div></td>
<td width="180"><div align="center">ชื่อผู้ใช้งาน</div></td>
<td width="120"><div align="center">ตำแหน่ง</div></td>
<td width="90"><div align="center">รหัสผ่าน</div></td>
<td width="170"><div align="center"></div></td>
</tr>
<?php do { ?>
<tr>
<td height="28"><input name="textfield" type="text" value="<?php echo $row_rem['user_id']; ?>" size="30" maxlength="30"></td>
<td><input name="textfield" type="text" value="<?php echo $row_rem['username']; ?>" size="30" maxlength="30"></td>
<td><input name="textfield" type="text" value="<?php echo $row_rem['p_pos']; ?>" size="20" maxlength="20"></td>
<td><input name="textfield" type="password" value="<?php echo $row_rem['pass_id']; ?>" size="15" maxlength="15"></td>
<td bordercolor="#660033" bgcolor="#FFCC66"><div align="center">
<div align="center">
<input name="Submit3" type="submit" id="Submit3" value="แก้ไข">
<?php } while ($row_rem = mysql_fetch_assoc($rem)); ?>
</div>
</table>
</form>
</body>
<?php
mysql_free_result($rem);
mysql_free_result($rem_1);
?>
</html>Tag : - - - -
Date :
2009-06-24 16:02:51
By :
preapo
View :
1089
Reply :
3
ข้อมูลที่เป็น Primary Key หรือ UNIQUE ซ้ำครับ
Date :
2009-06-25 13:38:36
By :
webmaster
ถูกต้องครับ มีค่าใน Primary key ซ้ำกันหรือฟิวส์นั้นมีข้อมูลอยู่แล้วคับ อย่างที่คุณ win บอก
Date :
2009-06-25 14:48:15
By :
backship
ขอบคุณคะตอนนี้เปลี่ยนแล้วคะจึงทำใไม่สามารถบันทึกข้อมูลลงฐานได้ มันไม่ขึ้นอะไรเลยคะ
Date :
2009-06-26 09:01:38
By :
preapo
Load balance : Server 00