cottonbuds2005 Posted October 13, 2009 Share Posted October 13, 2009 Hi, Im a newbie at PHP / MySql programming so pls excuse the messy coding. My code below allows me to search from db and displays results. From this result, Im going to insert a new row in my table instead of just updating. But I get Duplicate entry '..' for key 1 error. Pls help me thanks _______________ <?php require_once('../Connections/capinvdb_99k_itinventory.php'); ?> <?php //initialize the session session_start(); // ** Logout the current user. ** $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles session_unregister('MM_Username'); session_unregister('MM_UserGroup'); $logoutGoTo = "../index.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } ?> <?php //initialize the session // ** Logout the current user. ** $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles session_unregister('MM_Username'); session_unregister('MM_UserGroup'); $logoutGoTo = "../index.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } ?> <!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>Search and Create</title> <?php error_reporting(0); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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_insert"])) & ($_POST["MM_insert"] == "SearchandCreate")) { $insertSQL = sprintf("INSERT INTO assetsdb (EquipmentClassification, SBU, Username, Department, Division, Location, Floor, Brand, Model, HostName, EquipmentSpecifications, SerialNo, AssetNo, InvNo, InvDate, WorkOrder, WorksOrderDate, Supplier, Cost, DeliveryDate, DeliveryStatus, WarrantyExpiryDate, WarrantyCoverage, Movement, NewBUAssetNo, UpdatedBy, UpdatedDate, ReviewedBy, ReviewedDate, Remarks) VALUES ('.$EquipmentClassification.', '.$SBU.', '.$Username.', '.$Department.', '.$Division.', '.$Location.', '.$Floor.', '.$Brand.', '.$Model.', '.$HostName.', '.$EquipmentSpecifications.', '.$SerialNo.', '.$AssetNo.', '.$InvNo.', '.$InvDate.', '.$WorkOrder.', '.$WorksOrderDate.', '.$Supplier.', '.$Cost.', '.$DeliveryDate.', '.$DeliveryStatus.', '.$WarrantyExpiryDate.', '.$WarrantyCoverage.', '.$Movement.', '.$NewBUAssetNo.', '.$UpdatedBy.', '.$UpdatedDate.', '.$ReviewedBy.', '.$ReviewedDate.', '.$Remarks.')", GetSQLValueString($_POST['EquipmentClassification'], "text"), GetSQLValueString($_POST['SBU'], "text"), GetSQLValueString($_POST['Username'], "text"), GetSQLValueString($_POST['Dept'], "text"), GetSQLValueString($_POST['Div'], "text"), GetSQLValueString($_POST['Location'], "text"), GetSQLValueString($_POST['Floor'], "text"), GetSQLValueString($_POST['Brand'], "text"), GetSQLValueString($_POST['Model'], "text"), GetSQLValueString($_POST['HostName'], "text"), GetSQLValueString($_POST['EquipmentSpec'], "text"), GetSQLValueString($_POST['AssetNo'], "text"), GetSQLValueString($_POST['InvNo'], "text"), GetSQLValueString($_POST['InvDate'], "text"), GetSQLValueString($_POST['WO'], "text"), GetSQLValueString($_POST['WODate'], "text"), GetSQLValueString($_POST['Supplier'], "text"), GetSQLValueString($_POST['Cost'], "text"), GetSQLValueString($_POST['DeliveryDate'], "text"), GetSQLValueString($_POST['DeliveryStatus'], "text"), GetSQLValueString($_POST['WarrantyExpiryDate'], "text"), GetSQLValueString($_POST['WarrantyCoverage'], "text"), GetSQLValueString($_POST['Mov'], "text"), GetSQLValueString($_POST['BuNum'], "text"), GetSQLValueString($_POST['UpdatedBy'], "text"), GetSQLValueString($_POST['UpdatedDate'], "text"), GetSQLValueString($_POST['ReviewedBy'], "text"), GetSQLValueString($_POST['ReviewedDate'], "text"), GetSQLValueString($_POST['Remarks'], "text"), GetSQLValueString($_POST['SerialNo'], "text")); mysql_select_db($database_capinvdb_99k_itinventory, $capinvdb_99k_itinventory); $Result1 = mysql_query($insertSQL, $capinvdb_99k_itinventory); if($Result1!=1){ echo '<script language="JavaScript" type="text/javascript">alert("'.mysql_error().'")</script>'; }else if($Result1==1){ echo '<script language="JavaScript" type="text/javascript">alert("Serial No:'.$_POST['SerialNo'].' updated.")</script>'; header('refresh: 00; url=SearchandCreate.php'); } } $colname_SearchBySerial = "-1"; if (isset($_POST['SerialNo'])) { $colname_SearchBySerial = $_POST['SerialNo']; } mysql_select_db($database_capinvdb_99k_itinventory, $capinvdb_99k_itinventory); $query_SearchBySerial = sprintf("SELECT * FROM assetsdb WHERE SerialNo = %s", GetSQLValueString($colname_SearchBySerial, "text")); $SearchBySerial = mysql_query($query_SearchBySerial, $capinvdb_99k_itinventory) or die(mysql_error()); $row_SearchBySerial = mysql_fetch_assoc($SearchBySerial); $totalRows_SearchBySerial = mysql_num_rows($SearchBySerial); $colname_SearchByAssetNo = "-1"; if (isset($_POST['AssetNo'])) { $colname_SearchByAssetNo = $_POST['AssetNo']; } mysql_select_db($database_capinvdb_99k_itinventory, $capinvdb_99k_itinventory); $query_SearchByAssetNo = sprintf("SELECT * FROM assetsdb WHERE AssetNo = %s", GetSQLValueString($colname_SearchByAssetNo, "text")); $SearchByAssetNo = mysql_query($query_SearchByAssetNo, $capinvdb_99k_itinventory) or die(mysql_error()); $row_SearchByAssetNo = mysql_fetch_assoc($SearchByAssetNo); $totalRows_SearchByAssetNo = mysql_num_rows($SearchByAssetNo); ?> <link rel="stylesheet" type="text/css" href="stylesheet/style.css"> </head> <body> <h3>Search and Create New Record</h3> <table> <tr> <td><form action="" method="post" name="SearchSerial"> <input name="SerialNo" type="text" /><input name="SearchBySerialNo" type="submit" value="Search By Serial No" class="btn"/> </form></td> <td><form action="" method="post" name="SearchAsset"> <input name="AssetNo" type="text" /><input name="SearchByAssetNo" type="submit" value="Search By Asset No" class="btn"/> <input type="button" name="backtomain2" value="Back to main" onclick="window.location.href='../main.php'" class="btn"/> </form></td> <td><form action="<?php echo $logoutAction ?>" method="post" name="logout"><input name="logout" type="submit" value="Logout" class="mainbtn"/></form> </td> </tr> </table> <form id="SearchandCreate" name="SearchandCreate" method="POST" action="<?php echo $editFormAction; ?>"> <table border="1"> <tr> <th> </th> <th>Equipment Classification</th> <th>SBU</th> <th>Username</th> <th>Department</th> <th>Division</th> <th>Location</th> <th>Floor</th> <th>Brand</th> <th>Model</th> <th>Host Name</th> <th>Equipment Specifications</th> <th>Serial No</th> <th>Asset No/Inventory No</th> <th>Invoice No</th> <th>Invoice Date</th> <th>Work Order/Purchase Order</th> <th>Works Order/Purchase Date</th> <th>Supplier</th> <th>Cost (S$)</th> <th>Delivery Date</th> <th>Delivery Status</th> <th>Warranty Expiry Date</th> <th>Warranty Coverage</th> <th>IT Movement </th> <th>New BU Asset Number (for BU Transfer)</th> <th>Updated By</th> <th>Updated Date</th> <th>Reviewed By</th> <th>Reviewed Date</th> <th>Remarks</th> <th> </th> </tr> <?php if ($totalRows_SearchBySerial > 0) { // Show if recordset not empty ?> <?php do { ?> <tr> <td><input type="submit" name="Insert" id="Insert" value="Insert" class="btn"/></td> <td><input name="EquipmentClassification" type="text" id="Equipment Classification" value="<?php echo $row_SearchBySerial['EquipmentClassification']; ?>" /></td> <td><input name="SBU" type="text" id="SBU" value="<?php echo $row_SearchBySerial['SBU']; ?>" /></td> <td><input name="Username" type="text" id="Username" value="<?php echo $row_SearchBySerial['Username']; ?>" /></td> <td><input name="Dept" type="text" id="Dept" value="<?php echo $row_SearchBySerial['Department']; ?>" /></td> <td><input name="Div" type="text" id="Div" value="<?php echo $row_SearchBySerial['Division']; ?>" /></td> <td><input name="Location" type="text" id="Location" value="<?php echo $row_SearchBySerial['Location']; ?>" /></td> <td><input name="Floor" type="text" id="Floor" value="<?php echo $row_SearchBySerial['Floor']; ?>" /></td> <td><input name="Brand" type="text" id="Brand" value="<?php echo $row_SearchBySerial['Brand']; ?>" /></td> <td><input name="Model" type="text" id="Model" value="<?php echo $row_SearchBySerial['Model']; ?>" /></td> <td><input name="HostName" type="text" id="HostName" value="<?php echo $row_SearchBySerial['HostName']; ?>" /></td> <td><textarea name="EquipmentSpec" id="EquipmentSpec" cols="45" rows="3"><?php echo $row_SearchBySerial['EquipmentSpecifications']; ?></textarea></td> <td><input name="SerialNo" type="text" id="SerialNo" value="<?php echo $row_SearchBySerial['SerialNo']; ?>" readonly="readonly" /></td> <td><input name="AssetNo" type="text" id="AssetNo" value="<?php echo $row_SearchBySerial['AssetNo']; ?>" readonly="readonly" /></td> <td><input name="InvNo" type="text" id="InvNo" value="<?php echo $row_SearchBySerial['InvNo']; ?>" /></td> <td><input name="InvDate" type="text" id="InvDate" value="<?php echo $row_SearchBySerial['InvDate']; ?>" /></td> <td><input name="WO" type="text" id="WO" value="<?php echo $row_SearchBySerial['WorkOrder']; ?>" /></td> <td><input name="WODate" type="text" id="WODate" value="<?php echo $row_SearchBySerial['WorksOrderDate']; ?>" /></td> <td><input name="Supplier" type="text" id="Supplier" value="<?php echo $row_SearchBySerial['Supplier']; ?>" /></td> <td><input name="Cost" type="text" id="Cost" value="<?php echo $row_SearchBySerial['Cost']; ?>" /></td> <td><input name="DeliveryDate" type="text" id="DeliveryDate" value="<?php echo $row_SearchBySerial['DeliveryDate']; ?>" /></td> <td><input name="DeliveryStatus" type="text" id="DeliveryStatus" value="<?php echo $row_SearchBySerial['DeliveryStatus']; ?>" /></td> <td><input name="WarrantyExpiryDate" type="text" id="WarrantyExpiryDate" value="<?php echo $row_SearchBySerial['WarrantyExpiryDate']; ?>" /></td> <td><input name="WarrantyCoverage" type="text" id="WarrantyCoverage" value="<?php echo $row_SearchBySerial['WarrantyCoverage']; ?>" /></td> <td><input name="Mov" type="text" id="Mov" value="<?php echo $row_SearchBySerial['Movement']; ?>" /></td> <td><input name="BuNum" type="text" id="BuNum" value="<?php echo $row_SearchBySerial['NewBUAssetNo']; ?>" /></td> <td><input name="UpdatedBy" type="text" id="UpdatedBy" value="<?php echo $row_SearchBySerial['UpdatedBy']; ?>" /></td> <td><input name="UpdatedDate" type="text" id="UpdatedDate" value="<?php echo $row_SearchBySerial['UpdatedDate']; ?>" /></td> <td><input name="ReviewedBy" type="text" id="ReviewedBy" value="<?php echo $row_SearchBySerial['ReviewedBy']; ?>" /></td> <td><input name="ReviewedDate" type="text" id="ReviewedDate" value="<?php echo $row_SearchBySerial['ReviewedDate']; ?>" /></td> <td><input name="Remarks" type="text" id="Remarks" value="<?php echo $row_SearchBySerial['Remarks']; ?>" /></td> <td><input type="submit" name="Insert" id="Insert" value="Insert" class="btn"/></td> </tr> <?php } while ($row_SearchBySerial = mysql_fetch_assoc($SearchBySerial)); ?> <?php } // Show if recordset not empty ?> <?php if ($totalRows_SearchByAssetNo > 0) { // Show if recordset not empty ?> <?php do { ?> <tr> <td><input type="submit" name="Insert" id="Insert" value="Insert" class="btn"/></td> <td><input name="EquipmentClassification" type="text" id="Equipment Classification" value="<?php echo $row_SearchByAssetNo['EquipmentClassification']; ?>" /></td> <td><input name="SBU" type="text" id="SBU" value="<?php echo $row_SearchByAssetNo['SBU']; ?>" /></td> <td><input name="Username" type="text" id="Username" value="<?php echo $row_SearchByAssetNo['Username']; ?>" /></td> <td><input name="Dept" type="text" id="Dept" value="<?php echo $row_SearchByAssetNo['Department']; ?>" /></td> <td><input name="Div" type="text" id="Div" value="<?php echo $row_SearchByAssetNo['Division']; ?>" /></td> <td><input name="Location" type="text" id="Location" value="<?php echo $row_SearchByAssetNo['Location']; ?>" /></td> <td><input name="Floor" type="text" id="Floor" value="<?php echo $row_SearchByAssetNo['Floor']; ?>" /></td> <td><input name="Brand" type="text" id="Brand" value="<?php echo $row_SearchByAssetNo['Brand']; ?>" /></td> <td><input name="Model" type="text" id="Model" value="<?php echo $row_SearchByAssetNo['Model']; ?>" /></td> <td><input name="HostName" type="text" id="HostName" value="<?php echo $row_SearchByAssetNo['HostName']; ?>" /></td> <td><textarea name="EquipmentSpec" id="EquipmentSpec" cols="45" rows="3"><?php echo $row_SearchByAssetNo['EquipmentSpecifications']; ?></textarea></td> <td><input name="SerialNo" type="text" id="SerialNo" value="<?php echo $row_SearchByAssetNo['SerialNo']; ?>" readonly="readonly"/></td> <td><input name="AssetNo" type="text" id="AssetNo" value="<?php echo $row_SearchByAssetNo['AssetNo']; ?>" readonly="readonly" /></td> <td><input name="InvNo" type="text" id="InvNo" value="<?php echo $row_SearchByAssetNo['InvNo']; ?>" /></td> <td><input name="InvDate" type="text" id="InvDate" value="<?php echo $row_SearchByAssetNo['InvDate']; ?>" /></td> <td><input name="WO" type="text" id="WO" value="<?php echo $row_SearchByAssetNo['WorkOrder']; ?>" /></td> <td><input name="WODate" type="text" id="WODate" value="<?php echo $row_SearchByAssetNo['WorksOrderDate']; ?>" /></td> <td><input name="Supplier" type="text" id="Supplier" value="<?php echo $row_SearchByAssetNo['Supplier']; ?>" /></td> <td><input name="Cost" type="text" id="Cost" value="<?php echo $row_SearchByAssetNo['Cost']; ?>" /></td> <td><input name="DeliveryDate" type="text" id="DeliveryDate" value="<?php echo $row_SearchByAssetNo['DeliveryDate']; ?>" /></td> <td><input name="DeliveryStatus" type="text" id="DeliveryStatus" value="<?php echo $row_SearchByAssetNo['DeliveryStatus']; ?>" /></td> <td><input name="WarrantyExpiryDate" type="text" id="WarrantyExpiryDate" value="<?php echo $row_SearchByAssetNo['WarrantyExpiryDate']; ?>" /></td> <td><input name="WarrantyCoverage" type="text" id="WarrantyCoverage" value="<?php echo $row_SearchByAssetNo['WarrantyCoverage']; ?>" /></td> <td><input name="Mov" type="text" id="Mov" value="<?php echo $row_SearchByAssetNo['Movement']; ?>" /></td> <td><input name="BuNum" type="text" id="BuNum" value="<?php echo $row_SearchByAssetNo['NewBUAssetNo']; ?>" /></td> <td><input name="UpdatedBy" type="text" id="UpdatedBy" value="<?php echo $row_SearchByAssetNo['UpdatedBy']; ?>" /></td> <td><input name="UpdatedDate" type="text" id="UpdatedDate" value="<?php echo $row_SearchByAssetNo['UpdatedDate']; ?>" /></td> <td><input name="ReviewedBy" type="text" id="ReviewedBy" value="<?php echo $row_SearchByAssetNo['ReviewedBy']; ?>" /></td> <td><input name="ReviewedDate" type="text" id="ReviewedDate" value="<?php echo $row_SearchByAssetNo['ReviewedDate']; ?>" /></td> <td><input name="Remarks" type="text" id="Remarks" value="<?php echo $row_SearchByAssetNo['Remarks']; ?>" /></td> <td><input type="submit" name="Update" id="Update" value="Update" class="btn"/></td> </tr> <?php } while ($row_SearchByAssetNo = mysql_fetch_assoc($SearchByAssetNo)); ?> <?php } // Show if recordset not empty ?> </table> <input type="hidden" name="MM_insert" value="SearchandCreate" /> </form> </body> </html> <?php mysql_free_result($SearchBySerial); mysql_free_result($SearchByAssetNo); ?> <?php require_once('../Connections/capinvdb_99k_itinventory.php'); ?> <?php //initialize the session session_start(); // ** Logout the current user. ** $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles session_unregister('MM_Username'); session_unregister('MM_UserGroup'); $logoutGoTo = "../index.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } ?> <?php //initialize the session // ** Logout the current user. ** $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles session_unregister('MM_Username'); session_unregister('MM_UserGroup'); $logoutGoTo = "../index.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } ?> <!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>Search and Create</title> <?php error_reporting(0); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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_insert"])) & ($_POST["MM_insert"] == "SearchandCreate")) { $insertSQL = sprintf("INSERT INTO assetsdb (EquipmentClassification, SBU, Username, Department, Division, Location, Floor, Brand, Model, HostName, EquipmentSpecifications, SerialNo, AssetNo, InvNo, InvDate, WorkOrder, WorksOrderDate, Supplier, Cost, DeliveryDate, DeliveryStatus, WarrantyExpiryDate, WarrantyCoverage, Movement, NewBUAssetNo, UpdatedBy, UpdatedDate, ReviewedBy, ReviewedDate, Remarks) VALUES ('.$EquipmentClassification.', '.$SBU.', '.$Username.', '.$Department.', '.$Division.', '.$Location.', '.$Floor.', '.$Brand.', '.$Model.', '.$HostName.', '.$EquipmentSpecifications.', '.$SerialNo.', '.$AssetNo.', '.$InvNo.', '.$InvDate.', '.$WorkOrder.', '.$WorksOrderDate.', '.$Supplier.', '.$Cost.', '.$DeliveryDate.', '.$DeliveryStatus.', '.$WarrantyExpiryDate.', '.$WarrantyCoverage.', '.$Movement.', '.$NewBUAssetNo.', '.$UpdatedBy.', '.$UpdatedDate.', '.$ReviewedBy.', '.$ReviewedDate.', '.$Remarks.')", GetSQLValueString($_POST['EquipmentClassification'], "text"), GetSQLValueString($_POST['SBU'], "text"), GetSQLValueString($_POST['Username'], "text"), GetSQLValueString($_POST['Dept'], "text"), GetSQLValueString($_POST['Div'], "text"), GetSQLValueString($_POST['Location'], "text"), GetSQLValueString($_POST['Floor'], "text"), GetSQLValueString($_POST['Brand'], "text"), GetSQLValueString($_POST['Model'], "text"), GetSQLValueString($_POST['HostName'], "text"), GetSQLValueString($_POST['EquipmentSpec'], "text"), GetSQLValueString($_POST['AssetNo'], "text"), GetSQLValueString($_POST['InvNo'], "text"), GetSQLValueString($_POST['InvDate'], "text"), GetSQLValueString($_POST['WO'], "text"), GetSQLValueString($_POST['WODate'], "text"), GetSQLValueString($_POST['Supplier'], "text"), GetSQLValueString($_POST['Cost'], "text"), GetSQLValueString($_POST['DeliveryDate'], "text"), GetSQLValueString($_POST['DeliveryStatus'], "text"), GetSQLValueString($_POST['WarrantyExpiryDate'], "text"), GetSQLValueString($_POST['WarrantyCoverage'], "text"), GetSQLValueString($_POST['Mov'], "text"), GetSQLValueString($_POST['BuNum'], "text"), GetSQLValueString($_POST['UpdatedBy'], "text"), GetSQLValueString($_POST['UpdatedDate'], "text"), GetSQLValueString($_POST['ReviewedBy'], "text"), GetSQLValueString($_POST['ReviewedDate'], "text"), GetSQLValueString($_POST['Remarks'], "text"), GetSQLValueString($_POST['SerialNo'], "text")); mysql_select_db($database_capinvdb_99k_itinventory, $capinvdb_99k_itinventory); $Result1 = mysql_query($insertSQL, $capinvdb_99k_itinventory); if($Result1!=1){ echo '<script language="JavaScript" type="text/javascript">alert("'.mysql_error().'")</script>'; }else if($Result1==1){ echo '<script language="JavaScript" type="text/javascript">alert("Serial No:'.$_POST['SerialNo'].' updated.")</script>'; header('refresh: 00; url=SearchandCreate.php'); } } $colname_SearchBySerial = "-1"; if (isset($_POST['SerialNo'])) { $colname_SearchBySerial = $_POST['SerialNo']; } mysql_select_db($database_capinvdb_99k_itinventory, $capinvdb_99k_itinventory); $query_SearchBySerial = sprintf("SELECT * FROM assetsdb WHERE SerialNo = %s", GetSQLValueString($colname_SearchBySerial, "text")); $SearchBySerial = mysql_query($query_SearchBySerial, $capinvdb_99k_itinventory) or die(mysql_error()); $row_SearchBySerial = mysql_fetch_assoc($SearchBySerial); $totalRows_SearchBySerial = mysql_num_rows($SearchBySerial); $colname_SearchByAssetNo = "-1"; if (isset($_POST['AssetNo'])) { $colname_SearchByAssetNo = $_POST['AssetNo']; } mysql_select_db($database_capinvdb_99k_itinventory, $capinvdb_99k_itinventory); $query_SearchByAssetNo = sprintf("SELECT * FROM assetsdb WHERE AssetNo = %s", GetSQLValueString($colname_SearchByAssetNo, "text")); $SearchByAssetNo = mysql_query($query_SearchByAssetNo, $capinvdb_99k_itinventory) or die(mysql_error()); $row_SearchByAssetNo = mysql_fetch_assoc($SearchByAssetNo); $totalRows_SearchByAssetNo = mysql_num_rows($SearchByAssetNo); ?> <link rel="stylesheet" type="text/css" href="stylesheet/style.css"> </head> <body> <h3>Search and Create New Record</h3> <table> <tr> <td><form action="" method="post" name="SearchSerial"> <input name="SerialNo" type="text" /><input name="SearchBySerialNo" type="submit" value="Search By Serial No" class="btn"/> </form></td> <td><form action="" method="post" name="SearchAsset"> <input name="AssetNo" type="text" /><input name="SearchByAssetNo" type="submit" value="Search By Asset No" class="btn"/> <input type="button" name="backtomain2" value="Back to main" onclick="window.location.href='../main.php'" class="btn"/> </form></td> <td><form action="<?php echo $logoutAction ?>" method="post" name="logout"><input name="logout" type="submit" value="Logout" class="mainbtn"/></form> </td> </tr> </table> <form id="SearchandCreate" name="SearchandCreate" method="POST" action="<?php echo $editFormAction; ?>"> <table border="1"> <tr> <th> </th> <th>Equipment Classification</th> <th>SBU</th> <th>Username</th> <th>Department</th> <th>Division</th> <th>Location</th> <th>Floor</th> <th>Brand</th> <th>Model</th> <th>Host Name</th> <th>Equipment Specifications</th> <th>Serial No</th> <th>Asset No/Inventory No</th> <th>Invoice No</th> <th>Invoice Date</th> <th>Work Order/Purchase Order</th> <th>Works Order/Purchase Date</th> <th>Supplier</th> <th>Cost (S$)</th> <th>Delivery Date</th> <th>Delivery Status</th> <th>Warranty Expiry Date</th> <th>Warranty Coverage</th> <th>IT Movement </th> <th>New BU Asset Number (for BU Transfer)</th> <th>Updated By</th> <th>Updated Date</th> <th>Reviewed By</th> <th>Reviewed Date</th> <th>Remarks</th> <th> </th> </tr> <?php if ($totalRows_SearchBySerial > 0) { // Show if recordset not empty ?> <?php do { ?> <tr> <td><input type="submit" name="Insert" id="Insert" value="Insert" class="btn"/></td> <td><input name="EquipmentClassification" type="text" id="Equipment Classification" value="<?php echo $row_SearchBySerial['EquipmentClassification']; ?>" /></td> <td><input name="SBU" type="text" id="SBU" value="<?php echo $row_SearchBySerial['SBU']; ?>" /></td> <td><input name="Username" type="text" id="Username" value="<?php echo $row_SearchBySerial['Username']; ?>" /></td> <td><input name="Dept" type="text" id="Dept" value="<?php echo $row_SearchBySerial['Department']; ?>" /></td> <td><input name="Div" type="text" id="Div" value="<?php echo $row_SearchBySerial['Division']; ?>" /></td> <td><input name="Location" type="text" id="Location" value="<?php echo $row_SearchBySerial['Location']; ?>" /></td> <td><input name="Floor" type="text" id="Floor" value="<?php echo $row_SearchBySerial['Floor']; ?>" /></td> <td><input name="Brand" type="text" id="Brand" value="<?php echo $row_SearchBySerial['Brand']; ?>" /></td> <td><input name="Model" type="text" id="Model" value="<?php echo $row_SearchBySerial['Model']; ?>" /></td> <td><input name="HostName" type="text" id="HostName" value="<?php echo $row_SearchBySerial['HostName']; ?>" /></td> <td><textarea name="EquipmentSpec" id="EquipmentSpec" cols="45" rows="3"><?php echo $row_SearchBySerial['EquipmentSpecifications']; ?></textarea></td> <td><input name="SerialNo" type="text" id="SerialNo" value="<?php echo $row_SearchBySerial['SerialNo']; ?>" readonly="readonly" /></td> <td><input name="AssetNo" type="text" id="AssetNo" value="<?php echo $row_SearchBySerial['AssetNo']; ?>" readonly="readonly" /></td> <td><input name="InvNo" type="text" id="InvNo" value="<?php echo $row_SearchBySerial['InvNo']; ?>" /></td> <td><input name="InvDate" type="text" id="InvDate" value="<?php echo $row_SearchBySerial['InvDate']; ?>" /></td> <td><input name="WO" type="text" id="WO" value="<?php echo $row_SearchBySerial['WorkOrder']; ?>" /></td> <td><input name="WODate" type="text" id="WODate" value="<?php echo $row_SearchBySerial['WorksOrderDate']; ?>" /></td> <td><input name="Supplier" type="text" id="Supplier" value="<?php echo $row_SearchBySerial['Supplier']; ?>" /></td> <td><input name="Cost" type="text" id="Cost" value="<?php echo $row_SearchBySerial['Cost']; ?>" /></td> <td><input name="DeliveryDate" type="text" id="DeliveryDate" value="<?php echo $row_SearchBySerial['DeliveryDate']; ?>" /></td> <td><input name="DeliveryStatus" type="text" id="DeliveryStatus" value="<?php echo $row_SearchBySerial['DeliveryStatus']; ?>" /></td> <td><input name="WarrantyExpiryDate" type="text" id="WarrantyExpiryDate" value="<?php echo $row_SearchBySerial['WarrantyExpiryDate']; ?>" /></td> <td><input name="WarrantyCoverage" type="text" id="WarrantyCoverage" value="<?php echo $row_SearchBySerial['WarrantyCoverage']; ?>" /></td> <td><input name="Mov" type="text" id="Mov" value="<?php echo $row_SearchBySerial['Movement']; ?>" /></td> <td><input name="BuNum" type="text" id="BuNum" value="<?php echo $row_SearchBySerial['NewBUAssetNo']; ?>" /></td> <td><input name="UpdatedBy" type="text" id="UpdatedBy" value="<?php echo $row_SearchBySerial['UpdatedBy']; ?>" /></td> <td><input name="UpdatedDate" type="text" id="UpdatedDate" value="<?php echo $row_SearchBySerial['UpdatedDate']; ?>" /></td> <td><input name="ReviewedBy" type="text" id="ReviewedBy" value="<?php echo $row_SearchBySerial['ReviewedBy']; ?>" /></td> <td><input name="ReviewedDate" type="text" id="ReviewedDate" value="<?php echo $row_SearchBySerial['ReviewedDate']; ?>" /></td> <td><input name="Remarks" type="text" id="Remarks" value="<?php echo $row_SearchBySerial['Remarks']; ?>" /></td> <td><input type="submit" name="Insert" id="Insert" value="Insert" class="btn"/></td> </tr> <?php } while ($row_SearchBySerial = mysql_fetch_assoc($SearchBySerial)); ?> <?php } // Show if recordset not empty ?> <?php if ($totalRows_SearchByAssetNo > 0) { // Show if recordset not empty ?> <?php do { ?> <tr> <td><input type="submit" name="Insert" id="Insert" value="Insert" class="btn"/></td> <td><input name="EquipmentClassification" type="text" id="Equipment Classification" value="<?php echo $row_SearchByAssetNo['EquipmentClassification']; ?>" /></td> <td><input name="SBU" type="text" id="SBU" value="<?php echo $row_SearchByAssetNo['SBU']; ?>" /></td> <td><input name="Username" type="text" id="Username" value="<?php echo $row_SearchByAssetNo['Username']; ?>" /></td> <td><input name="Dept" type="text" id="Dept" value="<?php echo $row_SearchByAssetNo['Department']; ?>" /></td> <td><input name="Div" type="text" id="Div" value="<?php echo $row_SearchByAssetNo['Division']; ?>" /></td> <td><input name="Location" type="text" id="Location" value="<?php echo $row_SearchByAssetNo['Location']; ?>" /></td> <td><input name="Floor" type="text" id="Floor" value="<?php echo $row_SearchByAssetNo['Floor']; ?>" /></td> <td><input name="Brand" type="text" id="Brand" value="<?php echo $row_SearchByAssetNo['Brand']; ?>" /></td> <td><input name="Model" type="text" id="Model" value="<?php echo $row_SearchByAssetNo['Model']; ?>" /></td> <td><input name="HostName" type="text" id="HostName" value="<?php echo $row_SearchByAssetNo['HostName']; ?>" /></td> <td><textarea name="EquipmentSpec" id="EquipmentSpec" cols="45" rows="3"><?php echo $row_SearchByAssetNo['EquipmentSpecifications']; ?></textarea></td> <td><input name="SerialNo" type="text" id="SerialNo" value="<?php echo $row_SearchByAssetNo['SerialNo']; ?>" readonly="readonly"/></td> <td><input name="AssetNo" type="text" id="AssetNo" value="<?php echo $row_SearchByAssetNo['AssetNo']; ?>" readonly="readonly" /></td> <td><input name="InvNo" type="text" id="InvNo" value="<?php echo $row_SearchByAssetNo['InvNo']; ?>" /></td> <td><input name="InvDate" type="text" id="InvDate" value="<?php echo $row_SearchByAssetNo['InvDate']; ?>" /></td> <td><input name="WO" type="text" id="WO" value="<?php echo $row_SearchByAssetNo['WorkOrder']; ?>" /></td> <td><input name="WODate" type="text" id="WODate" value="<?php echo $row_SearchByAssetNo['WorksOrderDate']; ?>" /></td> <td><input name="Supplier" type="text" id="Supplier" value="<?php echo $row_SearchByAssetNo['Supplier']; ?>" /></td> <td><input name="Cost" type="text" id="Cost" value="<?php echo $row_SearchByAssetNo['Cost']; ?>" /></td> <td><input name="DeliveryDate" type="text" id="DeliveryDate" value="<?php echo $row_SearchByAssetNo['DeliveryDate']; ?>" /></td> <td><input name="DeliveryStatus" type="text" id="DeliveryStatus" value="<?php echo $row_SearchByAssetNo['DeliveryStatus']; ?>" /></td> <td><input name="WarrantyExpiryDate" type="text" id="WarrantyExpiryDate" value="<?php echo $row_SearchByAssetNo['WarrantyExpiryDate']; ?>" /></td> <td><input name="WarrantyCoverage" type="text" id="WarrantyCoverage" value="<?php echo $row_SearchByAssetNo['WarrantyCoverage']; ?>" /></td> <td><input name="Mov" type="text" id="Mov" value="<?php echo $row_SearchByAssetNo['Movement']; ?>" /></td> <td><input name="BuNum" type="text" id="BuNum" value="<?php echo $row_SearchByAssetNo['NewBUAssetNo']; ?>" /></td> <td><input name="UpdatedBy" type="text" id="UpdatedBy" value="<?php echo $row_SearchByAssetNo['UpdatedBy']; ?>" /></td> <td><input name="UpdatedDate" type="text" id="UpdatedDate" value="<?php echo $row_SearchByAssetNo['UpdatedDate']; ?>" /></td> <td><input name="ReviewedBy" type="text" id="ReviewedBy" value="<?php echo $row_SearchByAssetNo['ReviewedBy']; ?>" /></td> <td><input name="ReviewedDate" type="text" id="ReviewedDate" value="<?php echo $row_SearchByAssetNo['ReviewedDate']; ?>" /></td> <td><input name="Remarks" type="text" id="Remarks" value="<?php echo $row_SearchByAssetNo['Remarks']; ?>" /></td> <td><input type="submit" name="Update" id="Update" value="Update" class="btn"/></td> </tr> <?php } while ($row_SearchByAssetNo = mysql_fetch_assoc($SearchByAssetNo)); ?> <?php } // Show if recordset not empty ?> </table> <input type="hidden" name="MM_insert" value="SearchandCreate" /> </form> </body> </html> <?php mysql_free_result($SearchBySerial); mysql_free_result($SearchByAssetNo); ?> Quote Link to comment https://forums.phpfreaks.com/topic/177552-duplicate-entry-for-key-1-error-pls-help/ Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 im not reading through your entire page that you just slapped in the post. post the relavent code between code/php tags Quote Link to comment https://forums.phpfreaks.com/topic/177552-duplicate-entry-for-key-1-error-pls-help/#findComment-936177 Share on other sites More sharing options...
ILMV Posted October 13, 2009 Share Posted October 13, 2009 Oh dear god my eyes! Please post relevant code, I cba to trawl through to find your error. Quote Link to comment https://forums.phpfreaks.com/topic/177552-duplicate-entry-for-key-1-error-pls-help/#findComment-936179 Share on other sites More sharing options...
GKWelding Posted October 13, 2009 Share Posted October 13, 2009 without reading your code it sounds like the primary key, or unique index, on the mysql table your inserting into is not set to auto increment so it's complaining that the entry you're trying to insert has the same unique ID as an already existing entry, and by the laws of common sense you cannot have 2 unique ID's as the same value. Quote Link to comment https://forums.phpfreaks.com/topic/177552-duplicate-entry-for-key-1-error-pls-help/#findComment-936184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.