okay after i updated the name field in my form i still get the error message saying : Notice : Undefined index: name in /opt/lampp/htdocs/create-nearmiss.php on line 57
Here is my full code. Kindly help.
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You have to log in first";
header('location: login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: login.php");
}
?>
<?php
$host="localhost";
$username="root";
$pass="";
$db="registration";
$conn=mysqli_connect($host,$username,$pass,$db);
if(!$conn){
die("Database connection error");
}
// insert query for register page
if(isset($_POST['ronel'])){
$image = $_FILES['name']['name'];
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["name"]["name"]);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif","pdf");
// Check extension
if( in_array($imageFileType,$extensions_arr) )
{
$details=$_POST['details'];
$location=$_POST['location'];
$checkbox=$_POST['checkbox'];
$injured=$_POST['injured'];
$agegender=$_POST['agegender'];
$contact=$_POST['contact'];
$empid=$_POST['empid'];
$dept=$_POST['dept'];
$organization=$_POST['organization'];
$summary=$_POST['summary'];
$name=$_POST['name'];
$outcome=$_POST['outcome'];
$cause=$_POST['cause'];
$action=$_POST['action'];
$reportedname=$_POST['reportedname'];
$position=$_POST['position'];
$organisation=$_POST['organisation'];
$reportedcontact=$_POST['reportedcontact'];
$reporteddept=$_POST['reporteddept'];
$status="Pending";
$comment=$_POST['comment'];
$query="INSERT INTO `proposals` (`details`,`location`,`date`,`time`,`checkbox`,`injured`,`agegender`,`contact`,`empid`,`dept` ,`organization`,`summary`,`image`,`outcome`,`cause`,`action`,`reportedname`,`position`,`organisation`,`reportedcontact`,`reporteddept`,`status`,`comment`) VALUES ('$details','$location', current_timestamp(),current_timestamp(),'$checkbox','$injured','$agegender','$contact','$empid','$dept' ,'$organization','$summary','$image','$outcome','$cause','$action','$reportedname','$position','$organisation','$reportedcontact','$reporteddept','$status','$comment')";
$res=mysqli_query($conn,$query);
if($res){
$_SESSION['success']="Not Inserted successfully!";
header('Location:');
}else{
echo "<script>alert('Proposal not applied!');</script>";
}
// Upload file
move_uploaded_file($_FILES['name']['tmp_name'],$target_dir.$image);
}
}
date_default_timezone_set("Asia/Kolkata");
?>
<html>
<body style="background-color:F8FFFF;">
<table style="position:absolute; bottom:83.2%; left:226px; width:66.3%; height:16.5%;">
<tr>
<th style="font-weight:600; font-size:18px">ONGC TRIPURA POWER COMPANY LIMITED</th>
</tr>
<tr>
<td style="font-weight:600; font-size:18px">INITIAL EHS INCIDENT REPORT FORM OTPC/SOP/EHS/001/R1</td>
</tr>
</table>
<div class="container">
<img src="otpc1" alt="Paris" style="width:130px; height:75px; border: 1px solid #ddd;
border-radius: 4px; position: relative;
left: 85%; bottom:17px;
padding: 10px;">
<img src="otpc" alt="Paris" style="width:170px; height:75px; border: 1px solid #ddd;
border-radius: 4px; position: relative;
right:140px; bottom:16px;
padding: 15px;">
</div>
<div class="col-xs-6 col-xs-push-3 well">
<form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="ronel" value="">
<fieldset style="position:relative; width:95%; top:0px; left:10px;">
<legend>NEW PROPOSAL NO.</legend>
<!----left box----------->
<!----right box----------->
<div class="col-xs-9">
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="font-size:16px;color:black;"><b>Details of Incident:</b></label><br>
<div class="col-lg-9">
<textarea rows="5" cols="110" name="details" class="form-control" maxlength="1000" onkeyup="textCounter(this,'counter4',1000);"></textarea><br><input style="position:absolute; left:75.3%; top:102px;" disabled maxlength="3" size="3" value="1000" id="counter4">
</div>
</div><br>
<fieldset style="position:relative; width:73.05%; height:50px; border:1px solid gray;">
<div class="form-group" style="position:relative; left:80px; top:-8px;">
<label style="position:relative; right:80px; top:25px;" for="inputEmail" class="col-lg-3"><b>Location:</b></label>
<div class="col-lg-9">
<textarea name="location" class="form-control" rows="2" cols="56" maxlength="100" onkeyup="textCounter(this,'counter5',100);"></textarea><input style="position:absolute; left:54%; bottom:0px;" disabled maxlength="3" size="2" value="100" id="counter5">
</div>
</div>
<div class="form-group" style="position:absolute; left:638px; bottom:22px;">
<label style="position:relative; right:58px; top:20px;" for="inputEmail" class="col-lg-3"><b>Date:</b></label>
<div class="col-lg-9">
<textarea style="position:relative; top:0px;right:19%;" cols="10" rows="1" disabled><?php echo date('Y-m-d'); ?>
</textarea>
</div>
</div>
<div class="form-group" style="position:relative; left:780px; bottom:54px;">
<label style="position:relative; right:67px; top:20px;" for="inputEmail" class="col-lg-3"><b>Time:</b></label>
<div class="col-lg-9">
<textarea style="position:relative; top:0px;right:3%;" cols="10" rows="1" disabled><?php
date_default_timezone_set("Asia/Kolkata");
echo date("h:i:sa");
?>
</textarea>
</div>
</div>
</fieldset>
<br>
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="font-size:16px;color:black;"><b>Classification(Tick the appropriate one, Leave blank if you find it difficulty):</b></label>
<div class="col-lg-9" name="checkbox">
<table>
<tr>
<th>Nearmisscase</th>
<th>First Aid Case</th>
<th>Lost Time Injury</th>
<th>Fatal</th>
<th>Fire</th>
<th>Emission/Discharge/Spill/Leak(Abnormal)</th>
<th>Property Damage</th>
<th>HIPO</th>
</tr>
<tr>
<td><input type="checkbox" value="Nearmiss case" name="checkbox"></td>
<td><input type="checkbox" value="First Aid Case" name="checkbox"></td>
<td><input type="checkbox" value="Lost Time Injury" name="checkbox"></td>
<td><input type="checkbox" value="Fatal" name="checkbox"></td>
<td><input type="checkbox" value="Fire" name="checkbox"></td>
<td><input type="checkbox" value="Emission/Discharge/Spill/Leak(Abnormal)" name="checkbox"></td>
<td><input type="checkbox" value="Property Damage" name="checkbox"></td>
<td><input type="checkbox" value="HIPO" name="checkbox"></td>
</tr>
</table>
<style>
table {
font-family: sans-serif;
border-collapse: collapse;
width: 75.5%;
font-size: 15px;
}
td,
th {
border: 1px solid black;
text-align: center;
padding: 2px;
font-weight: normal;
}
</style>
</div>
</div>
<br>
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="font-size:17px;color:black;"><b>Details of Injured :</b></label>
<br>
<label for="inputEmail" class="col-lg-3"><b>Name:</b></label>
<div class="col-lg-9">
<textarea name="injured" cols="25" rows="1" class="form-control"></textarea>
</div>
</div>
<div class="form-group" style="position:relative; left:20%; bottom:39px;">
<label for="inputEmail" class="col-lg-3"><b>Age/Gender:</b></label>
<div class="col-lg-9">
<textarea name="agegender" class="form-control" cols="3" rows="1"></textarea>
</div>
</div>
<div class="form-group" style="position:relative; left:29%; bottom:78px;">
<label for="inputEmail" class="col-lg-3"><b>Contact:</b></label>
<div class="col-lg-9">
<textarea name="contact" class="form-control" cols="9" rows="1"></textarea>
</div>
</div>
<div class="form-group" style="position:absolute; left:1.2%; top:26.5%;">
<label for="inputEmail" class="col-lg-3"><b>Employee ID:</b></label>
<div class="col-lg-9">
<textarea name="empid" class="form-control" cols="3" rows="1"></textarea>
</div>
</div>
<div class="form-group" style="position:relative; left:39%; bottom:117px;">
<label for="inputEmail" class="col-lg-3"><b>Organization:</b></label>
<div class="col-lg-9">
<input type="text" name="organization" class="form-control">
</div>
</div>
<div class="form-group" style="position:absolute; left:55%; bottom:74%;">
<label for="inputEmail" class="col-lg-3"><b>Department:</b></label>
<div class="col-lg-9">
<select name="dept" class="form-control">
<option value="">---------Select Dept--------</option>
<option value="MMD">MMD</option>
<option value="O&M">O&M</option>
<option value="Civil">Civil</option>
<option value="C&M">C&M</option>
<option value="Logistics">Logistics</option>
<option value="HR & ADMIN">HR & ADMIN</option>
<option value="Fire & Safety">Fire & Safety</option>
<option value="IT & MIS">IT & MIS</option>
<option value="F&M">F&M</option>
<option value="EMD">EMD</option>
<option value="C&I">C&I</option>
<option value="STORE">STORE</option>
<option value="EHS">EHS</option>
<option value="Tech Cell">Tech Cell</option>
<option value="Operation">Operation</option>
<option value="Chemist">Chemist</option>
</select>
</div>
</div><br><br>
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="position:relative; bottom:90px; font-size:17px;color:black;"><b>Summary Of Incident:</b></label>
<div class="col-lg-9" style="position:relative; bottom:90px;">
<textarea rows="8" cols="110" name="summary" class="form-control" maxlength="1000" onkeyup="textCounter(this,'counter3',1000);"></textarea><br><input style="position:absolute; left:72.5%;" disabled maxlength="3" size="3" value="1000" id="counter3">
</div>
</div>
<div class="form-group">
<label style="position:absolute; left:63%; top:425px;" for="inputEmail" class="col-lg-3"><b>Upload Images Here :</b></label><br><br>
<div class="col-lg-9">
<input style="position:absolute; left:78%; top:420px;" type="file" name="name" enctype="multipart/form-data" class="form-control" name="incident_reference" onchange="document.getElementById('inc_ref').src = window.URL.createObjectURL(this.files[0]); document.getElementById('inc_ref').className +='_active'; document.getElementById('inc_ref_span').className += '_hidden'">
</div><iframe id="inc_ref" class="form-group" width="220px" height="130px" style="position:absolute; left:78%; top:32%;"></iframe>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="position:relative; bottom:110px; font-size:17px;color:black;"><b>Potential outcome(Incase of Near Miss case or Potential Incident only):</b></label>
<div class="col-lg-9" style="position:relative; bottom:110px;">
<textarea rows="8" cols="110" name="outcome" class="form-control" maxlength="1000" maxlength="1000" onkeyup="textCounter(this,'counter2',1000);"></textarea><br><input style="position:absolute; left:76%; top:102px;" disabled maxlength="3" size="3" value="1000" id="counter2">
</div>
</div><br>
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="position:relative; bottom:110px; font-size:17px;color:black;"><b>Likely Cause:</b></label>
<div class="col-lg-9" style="position:relative; bottom:110px;">
<textarea rows="8" cols="110" name="cause" class="form-control" maxlength="1000" maxlength="1000" onkeyup="textCounter(this,'counter1',1000);"></textarea><br><input style="position:absolute; left:76%; top:102px;" disabled maxlength="3" size="3" value="1000" id="counter1">
</div>
</div><br>
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="position:relative; bottom:110px; font-size:17px;color:black;"><b>Immediate Action:</b></label>
<div class="col-lg-9" style="position:relative; bottom:110px;">
<textarea rows="8" cols="110" name="action" class="form-control" maxlength="1000" onkeyup="textCounter(this,'counter',1000);"></textarea><br><input style="position:absolute; left:76%; top:102px;" disabled maxlength="3" size="3" value="1000" id="counter">
</div>
</div><br>
<div class="form-group">
<label for="inputEmail" class="col-lg-3" style="position:relative; bottom:110px; font-size:17px;color:black;"><b>Incident reported by:</b></label>
<label for="inputEmail" class="col-lg-3" style="position:relative; bottom:80px; right:160px;"><b>Name:</b></label>
<div class="col-lg-9">
<input style="position:absolute; bottom:230px; left:10px;" type="text" name="reportedname" class="form-control">
</div>
</div>
<div class="form-group" style="position:relative; left:15%; bottom:100px;">
<label for="inputEmail" class="col-lg-3"><b>Position:</b></label>
<div class="col-lg-9">
<input type="text" name="position" class="form-control">
</div>
</div>
<div class="form-group" style="position:relative; left:31%; bottom:141px;">
<label for="inputEmail" class="col-lg-3"><b>Organisation:</b></label>
<div class="col-lg-9">
<input type="text" name="organisation" class="form-control">
</div>
</div>
<div class="form-group" style="position:relative; left:0%; bottom:130px;">
<label for="inputEmail" class="col-lg-3"><b>Contact:</b></label>
<div class="col-lg-9">
<input type="text" name="reportedcontact" class="form-control">
</div>
</div>
<div class="form-group" style="position:relative; left:175px; bottom:171px;">
<label for="inputEmail" class="col-lg-3"><b>Department:</b></label>
<div class="col-lg-9">
<input type="text" name="reporteddept" class="form-control">
</div>
</div>
<div class="col-lg-9">
<input type="hidden" name="status" class="form-control">
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-3"><b></b></label>
<div class="col-lg-9">
<input type="hidden" name="comment" class="form-control">
</div>
</div>
</div>
</fieldset>
<br>
<script type="text/javascript">
function confSubmit(form) {
if (confirm("Are you sure you want to submit the form?")) {
form.submit();
} else {
alert("You decided to not submit the form!");
}
}
</script>
<script>
function textCounter(field, field2, maxlimit) {
var countfield = document.getElementById(field2);
if (field.value.length > maxlimit) {
field.value = field.value.substring(0, maxlimit);
return false;
} else {
countfield.value = maxlimit - field.value.length;
}
}
</script>
<div class="form-group" style="position:absolute; left:33px;">
<div class="col-lg-12">
<button class="button1" type="reset" class="btn btn-default">Cancel</button>
<button class="button1" type="submit" class="btn btn-primary" onClick="confSubmit(this.form);">Submit</button>
<style>
.button1:hover {
background-color: #555555;
color: aqua;
border: 3px solid grey;
}
</style>
</div>
</div>
</form>
</div>
</body>
</html>