Thatâs more like it but my code is quite a bit different and generally based on php 5.4 or so.
What I am trying to achieve is when youâre adding item, the nextmaint being calculated at the point when you submit the form. So there is no data in the db as you are creating new record. Does it make clearer?
Hereâs the Add item page code
<?php require_once('Connections/eam.php'); ?>
<?php
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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO assets_hardware (
asset_type,
vendor,
model,
wsltoolno,
location,
date_purchase,
status,
user,
training,
maintenanceint,
comments,
monitor_size,
warranty,
subjecttoPAT,
spareparts,
addeddate,
manufacturerpn,
purchase_order,
lastmaint,
nextmaint,
maint1,
maint2,
maint3,
maint4,
maint5,
maint6,
maint7,
maint8,
maint9,
maint10,
serial)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['assets_hardware_type'], "text"),
GetSQLValueString($_POST['vendor'], "text"),
GetSQLValueString($_POST['model'], "text"),
GetSQLValueString($_POST['wsltoolno'], "text"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['date_purchase'], "date"),
GetSQLValueString($_POST['status'], "text"),
GetSQLValueString($_POST['user'], "text"),
GetSQLValueString($_POST['training'], "text"),
GetSQLValueString($_POST['maintenanceint'], "text"),
GetSQLValueString($_POST['comments'], "text"),
GetSQLValueString($_POST['monitor_size'], "int"),
GetSQLValueString($_POST['warranty'], "text"),
GetSQLValueString($_POST['subjecttoPAT'], "text"),
GetSQLValueString($_POST['spareparts'], "text"),
GetSQLValueString($_POST['addeddate'], "text"),
GetSQLValueString($_POST['manufacturerpn'], "text"),
GetSQLValueString($_POST['purchase_order'], "text"),
GetSQLValueString($_POST['date_purchase'], "date"),
GetSQLValueString($_POST['nextmaint'], "date"),
GetSQLValueString($_POST['maint1'], "text"),
GetSQLValueString($_POST['maint2'], "text"),
GetSQLValueString($_POST['maint3'], "text"),
GetSQLValueString($_POST['maint4'], "text"),
GetSQLValueString($_POST['maint5'], "text"),
GetSQLValueString($_POST['maint6'], "text"),
GetSQLValueString($_POST['maint7'], "text"),
GetSQLValueString($_POST['maint8'], "text"),
GetSQLValueString($_POST['maint9'], "text"),
GetSQLValueString($_POST['maint10'], "text"),
GetSQLValueString($_POST['serial'], "text")
);
mysql_select_db($database_eam, $eam);
$Result1 = mysql_query($insertSQL, $eam) or die(mysql_error());
$insertGoTo = "HardwareList.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_eam, $eam);
$query_rsVendors = "SELECT * FROM vendors ORDER BY vendor ASC";
$rsVendors = mysql_query($query_rsVendors, $eam) or die(mysql_error());
$row_rsVendors = mysql_fetch_assoc($rsVendors);
$totalRows_rsVendors = mysql_num_rows($rsVendors);
mysql_select_db($database_eam, $eam);
$query_rsPlatform = "SELECT * FROM assets_hardware_platform ORDER BY platform ASC";
$rsPlatform = mysql_query($query_rsPlatform, $eam) or die(mysql_error());
$row_rsPlatform = mysql_fetch_assoc($rsPlatform);
$totalRows_rsPlatform = mysql_num_rows($rsPlatform);
mysql_select_db($database_eam, $eam);
$query_rsHardwareType = "SELECT * FROM assets_hardware_type";
$rsHardwareType = mysql_query($query_rsHardwareType, $eam) or die(mysql_error());
$row_rsHardwareType = mysql_fetch_assoc($rsHardwareType);
$totalRows_rsHardwareType = mysql_num_rows($rsHardwareType);
mysql_select_db($database_eam, $eam);
$query_rsDivision = "SELECT * FROM division ORDER BY division ASC";
$rsDivision = mysql_query($query_rsDivision, $eam) or die(mysql_error());
$row_rsDivision = mysql_fetch_assoc($rsDivision);
$totalRows_rsDivision = mysql_num_rows($rsDivision);
mysql_select_db($database_eam, $eam);
$query_rscube = "SELECT * FROM cube ORDER BY cube ASC";
$rscube = mysql_query($query_rscube, $eam) or die(mysql_error());
$row_rscube = mysql_fetch_assoc($rscube);
$totalRows_rscube = mysql_num_rows($rscube);
mysql_select_db($database_eam, $eam);
$query_rsLocation = "SELECT * FROM location ORDER BY location ASC";
$rsLocation = mysql_query($query_rsLocation, $eam) or die(mysql_error());
$row_rsLocation = mysql_fetch_assoc($rsLocation);
$totalRows_rsLocation = mysql_num_rows($rsLocation);
mysql_select_db($database_eam, $eam);
$query_rsHardwareStatus = "SELECT * FROM assets_hardware_status ORDER BY assets_hardware_status ASC";
$rsHardwareStatus = mysql_query($query_rsHardwareStatus, $eam) or die(mysql_error());
$row_rsHardwareStatus = mysql_fetch_assoc($rsHardwareStatus);
$totalRows_rsHardwareStatus = mysql_num_rows($rsHardwareStatus);
mysql_select_db($database_eam, $eam);
$query_rsMonitorSize = "SELECT * FROM assets_hardware_monitor_size";
$rsMonitorSize = mysql_query($query_rsMonitorSize, $eam) or die(mysql_error());
$row_rsMonitorSize = mysql_fetch_assoc($rsMonitorSize);
$totalRows_rsMonitorSize = mysql_num_rows($rsMonitorSize);
?>
<meta name='viewport' content='width=500, initial-scale=1.5, maximum-scale=2.0, user-scalable=0'>
<?php $pageTitle="Add Asset"; ?>
<?php include('includes/header.php'); ?>
<fieldset>
<legend> Add Asset <i class="fa fa-print fa-lg" aria-hidden="true" onclick="goPrint()" onmouseover="" style="cursor: pointer;float:right;" ></i>
<i class="fa fa-home fa-lg" aria-hidden="true" onclick="location.href='index.php';" onmouseover="" style="cursor: pointer;float:right;"> </i>
<i class="fa fa-arrow-circle-left fa-lg" aria-hidden="true" onclick="goBack()" onmouseover="" style="cursor: pointer;float:right;"> </i> </legend>
<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
$file_type = $_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$expensions= array("jpeg","jpg","png","gif");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 3097152) {
$errors[]='File size must be no more than 2.95 MB';
}
if(empty($errors)==true) {
move_uploaded_file($file_tmp,"pictures/".$file_name);
}else{
print_r($errors);
}
}
?>
<p>
<label for="File">Select picture:</label>
<form action = "" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "image" />
<input type = "submit" value="Upload" />
<ul>
<?php echo $_FILES['image']['name']; ?>
<?php if(empty($_FILES)==false) { echo "<font color='green'><STRONG>HAS BEEN UPLOADED</STRONG></font>"; } ?>
</ul>
</form>
</p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1">
<p><label for="Platform">Asset Type: </label><select name="assets_hardware_type" required>
<option value="">-</option>
<?php
do {
?>
<option value="<?php echo $row_rsHardwareType['assets_hardware_type']?>"><?php echo $row_rsHardwareType['assets_hardware_type']?></option>
<?php
} while ($row_rsHardwareType = mysql_fetch_assoc($rsHardwareType));
$rows = mysql_num_rows($rsHardwareType);
if($rows > 0) {
mysql_data_seek($rsHardwareType, 0);
$row_rsHardwareType = mysql_fetch_assoc($rsHardwareType);
}
?>
</select> </p>
<p>
<label for="Platform">Maintenance Interval</label>
<select name="maintenanceint" required>
<option value=""> - </option>
<?php
do {
?>
<option value="<?php echo $row_rsPlatform['platform']?>"><?php echo $row_rsPlatform['platform']?></option>
<?php
} while ($row_rsPlatform = mysql_fetch_assoc($rsPlatform));
$rows = mysql_num_rows($rsPlatform);
if($rows > 0) {
mysql_data_seek($rsPlatform, 0);
$row_rsPlatform = mysql_fetch_assoc($rsPlatform);
}
?>
</select>
<span class="tiny">Months</span>
</p>
<p>
<label for="Vendor">Make</label>
<select name="vendor" required>
<option value=""> - </option>
<?php
do {
?>
<option value="<?php echo $row_rsVendors['vendor']?>"><?php echo $row_rsVendors['vendor']?></option>
<?php
} while ($row_rsVendors = mysql_fetch_assoc($rsVendors));
$rows = mysql_num_rows($rsVendors);
if($rows > 0) {
mysql_data_seek($rsVendors, 0);
$row_rsVendors = mysql_fetch_assoc($rsVendors);
}
?>
</select>
</p>
<p>
<label for="Model">Model</label>
<input name="model" type="text" size="20" maxlength="30" autocomplete="off" required />
</p>
<p>
<label for="Asset Tag">Serial Number</label>
<input name="serial" type="text" size="20" maxlength="40" autocomplete="off" />
</p>
<p>
<label for="Serial Number">WSL Tool Number</label>
<input name="wsltoolno" type="text" size="20" maxlength="30" autocomplete="off" required />
</p>
<p>
<label for="Asset Tag">Manufacturer P/N</label>
<input name="manufacturerpn" type="text" size="20" maxlength="30" autocomplete="off" required />
</p>
<p>
<label for="Purchase Order">Purchase Order</label>
<input name="purchase_order" type="text" size="20" maxlength="30" autocomplete="off" required />
</p>
<hr />
<p>
<label for="Date Purchased">Date Purchased</label>
<input type="text" name="date_purchase" value="" size="8" autocomplete="off" required />
<img src='images/scw.gif' title='Click Here' alt='Click Here' onclick="cal.select(document.forms['form1'].date_purchase,'anchor2','yyyy-MM-dd'); return false;" name="anchor2" id="anchor2" style="cursor:hand" /> </p>
<p>
<label for="Warranty Date">Warranty Date</label>
<input type="text" name="warranty" value="" size="8" autocomplete="off" required />
<img src='images/scw.gif' title='Click Here' alt='Click Here' onclick="cal.select(document.forms['form1'].warranty,'anchor1','yyyy-MM-dd'); return false;"
name="anchor1" id="anchor1" style="cursor:hand" /></p>
<p>
<label for="Status">Status</label>
<select name="status" required>
<option value=""> - </option>
<?php
do {
?>
<option value="<?php echo $row_rsHardwareStatus['assets_hardware_status']?>"><?php echo $row_rsHardwareStatus['assets_hardware_status']?></option>
<?php
} while ($row_rsHardwareStatus = mysql_fetch_assoc($rsHardwareStatus));
$rows = mysql_num_rows($rsHardwareStatus);
if($rows > 0) {
mysql_data_seek($rsHardwareStatus, 0);
$row_rsHardwareStatus = mysql_fetch_assoc($rsHardwareStatus);
}
?>
</select>
</p>
<hr />
<p>
<label for="User">Added By</label>
<input name="user" type="text" size="20" value="<?php echo $_SESSION['MM_Username'];?>" STYLE="background-color: #F2EFE9;" readonly />
</p>
<p>
<label for="User">Date Added</label>
<input type="text" name="addeddate" value="<?php echo date('Y-m-d'); ?> " size="20" STYLE="background-color: #F2EFE9;" readonly>
</p>
<p>
<label for="Division">Staff Training Req.?</label>
<select name="training" required>
<option value=""> - </option>
<?php
do {
?>
<option value="<?php echo $row_rsDivision['division']?>"><?php echo $row_rsDivision['division']?></option>
<?php
} while ($row_rsDivision = mysql_fetch_assoc($rsDivision));
$rows = mysql_num_rows($rsDivision);
if($rows > 0) {
mysql_data_seek($rsDivision, 0);
$row_rsDivision = mysql_fetch_assoc($rsDivision);
}
?>
</select>
</p>
<p>
<label for="Location">Location</label>
<select name="location" required>
<option value=""> - </option>
<?php
do {
?>
<option value="<?php echo $row_rsLocation['location']?>"><?php echo $row_rsLocation['location']?></option>
<?php
} while ($row_rsLocation = mysql_fetch_assoc($rsLocation));
$rows = mysql_num_rows($rsLocation);
if($rows > 0) {
mysql_data_seek($rsLocation, 0);
$row_rsLocation = mysql_fetch_assoc($rsLocation);
}
?>
</select>
</p>
<p>
<label for="Comments">Subject to PAT test</label>
<select name="subjecttoPAT" required>
<option value=""> - </option>
<?php
do {
?>
<option value="<?php echo $row_rscube['cube']?>"><?php echo $row_rscube['cube']?></option>
<?php
} while ($row_rscube = mysql_fetch_assoc($rscube));
$rows = mysql_num_rows($rscube);
if($rows > 0) {
mysql_data_seek($rscube, 0);
$row_rscube = mysql_fetch_assoc($rscube);
}
?>
</select>
</p>
<p>
<label for="Comments">Supplier & Spares</label>
<textarea name="spareparts" cols="32" rows="" wrap="virtual" ></textarea><span class="tiny"></span> </p>
<p>
<label for="Comments">Comments</label>
<textarea name="comments" cols="32"></textarea>
</p>
<hr />
<p> <center><h5>Maintenance Instructions</h5> </center></p>
<p>
<label for="maint1">Step 1</label>
<textarea name="maint1" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint2">Step 2</label>
<textarea name="maint2" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint3">Step 3</label>
<textarea name="maint3" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint4">Step 4</label>
<textarea name="maint4" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint5">Step 5</label>
<textarea name="maint5" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint6">Step 6</label>
<textarea name="maint6" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint7">Step 7</label>
<textarea name="maint7" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint8">Step 8</label>
<textarea name="maint8" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint9">Step 9</label>
<textarea name="maint9" type="text" cols="32" maxlength="250" ></textarea>
</p>
<p>
<label for="maint10">Step 10</label>
<textarea name="maint10" type="text" cols="32" maxlength="250" ></textarea>
</p>
<center> <p class="submit">
<input type="submit" value="Add" name="submit" />
</p></center>
<input type="hidden" name="MM_insert" value="form1" />
</fieldset>
</form>
<?php include('includes/footer.php'); ?>
<?php
mysql_free_result($rsVendors);
mysql_free_result($rsPlatform);
mysql_free_result($rsHardwareType);
mysql_free_result($rsDivision);
mysql_free_result($rsLocation);
mysql_free_result($rsHardwareStatus);
mysql_free_result($rsMonitorSize);
?>