Jump to content

Ronel

Members
  • Posts

    43
  • Joined

  • Last visited

Posts posted by Ronel

  1. <?php 
    $con = new mysqli("localhost","root","","loginsystem");
    
    $errors = array();
    if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['updatestock'])):
    /*
    echo "<pre>";
    print_r($_POST);	 
    echo "</pre>";
    */
    	$fields = array(	
    		 "itemname" => "Item Name"
    	    ,"purchaseid" => "Purchase ID"	
    	    ,"poqty" => "Purchase Order QTY"
    	    
    	); 
    	
    	foreach($fields as $field => $label):
    		if(empty($_POST[$field])): 
    			array_push($errors,"Please Enter ".$label);
    		endif;
    	endforeach;
    	
    	if(empty($errors)):
    		$sqlstockid = "SELECT `id` FROM `stock_orders` WHERE stockid = ? LIMIT 1"; 
    		$querystockid = $con->prepare($sqlstockid);	
    		$querystockid->bind_param("i", $_POST['stockid']); 
    		$querystockid->execute(); 
    		$resultstockid = $querystockid->get_result();	
    		$rowstockid = $resultstockid->fetch_assoc();
    
    		if(!empty($rowstockid)){ 
    			array_push($errors,"This Purchase ID already exists");
    		}
    	endif;		
    	
    	
    	if(empty($errors)):	
    	
    		$today = date('Y-m-d');
    		
    		$sqlstockorder = "INSERT INTO `stock_orders`(`id`, `stockid`, `poqty`, `remarks`) 
    		VALUES (?,?,?,?)";
    		
    		$querystockorder = $con->prepare($sqlstockorder);		
    		$querystockorder->bind_param("iiis", $_POST['id'], $_POST['stockid'], $_POST['poqty'], $remarks); 		
    		$querystockorder->execute();
    	
    	
    		$sqlstock = "UPDATE `stock` SET 
    		`stockqty` =  ABS(COALESCE(stockqty,0)+?)		
    		WHERE `id` = ?";
    		$querystock = $con->prepare($sqlstock);		
    		$querystock->bind_param("ii", $_POST['poqty'], $_POST['id']); 		
    		$querystock->execute();
    		$num = $con -> affected_rows;			
    		$message = (!empty($num) ? "Stock Updated" : 'No Changes Made');	
    		
    		header("refresh: 3; URL=edit.php");
    	endif;
    	
    endif;
    
    $sql = "SELECT `itemname` FROM `stock`";
    $res = mysqli_query($con, $sql);
    ?>
    
    
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script type="text/javascript" src="fetch.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
        </head>
    <body>
    	
            
    <?php	
    
    if(!empty($message)):
    	echo '<div style="width:500px; text-align: center; margin:20px auto;">'."\r";
    		echo '<span style="color:green"><b>'.$message.'</b></span></br >'."\r";
    	echo '</div>'."\r";
    endif;
    if(!empty($errors)):
    	echo '<div style="width:500px; text-align: center; margin:20px auto;">'."\r";
    	foreach($errors as $error):
    		echo '<span style="color:red">'.$error.'</span></br >'."\r";
    	endforeach;
    	echo '</div>'."\r";
    endif;
    
    
    
    			
    if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['itemname'])){
    
    		echo '<form action="" method="post">
    			<table class="table table-bordered">
    				<thead class="table-primary" style="white-space:nowrap;">
    				<th>Stock ID</th>	 
    				<th>Item Name</th>
    				<th>Stock Quantity</th>
    				<th>Remarks</th>				
    				<th>Update Stocks</th>
    				</thead>'."\r";	
    		
    			$sql = "select `id`, `itemname` from stock where itemname = ? "; 
    			$query = $con->prepare($sql);		
    			$query->bind_param("s",$_POST['itemname']); 		
    			$query->execute();
    			$result = $query->get_result();
    			while($rows = $result->fetch_assoc()){	
    			
    				//$purchaseid = (!empty($_POST['purchaseid']) ? $_POST['purchaseid'] : '');
    				//$poqty = (!empty($_POST['poqty']) ? $_POST['poqty'] : '');
    			
    				echo '<tr>
    					<td><input style="width:100%" type="text" name="id" value="'.$rows['id'].'" readonly /></td>
    					<td><input style="width:100%" type="text" name="itemname" value="'.$rows['itemname'].'" readonly /></td>
    					<td><input style="width:100%" type="text" name="stockqty" value="'.$stockqty.'" /></td>
    					<td><input style="width:100%" type="text" name="remarks" value="'.$remarks.'" /></td>					
    					<td><input style="width:100%" type="submit" name="updatestock" value="Update" /></td>
    				</tr>'."\r";
    			}
    		echo '</table>
    	</form>'."\r";
    	         
    }else{ 
    	echo '<b class="d-inline p-2 bg-primary text-white">Update Stock Here</b><hr>    
    	<b>Select Item to update :</b> 
        <select id="itemname" onchange="selectItem()">
            <option value="Select Item here" selected>Select Item here</option>'."\r";
    	
    		while ($rows = mysqli_fetch_array($res)){		 
    			echo '<option value="'.$rows['itemname'].'">'.$rows['itemname'].'</option>'."\r";
    		}
    		   
        echo '</select><br><br>'."\r";
    	echo '<div id="ans"></div>';
    }
    ?>
    	
    	<script type="text/javascript">
    		function selectItem(){
    			    var x = document.getElementById("itemname").value;
    			    
    			    $.ajax({
    			       url:"edit.php",
    			        method: "POST",
    			        data:{
    			            itemname : x
    			        },
    	        success:function(DataView){
    	        $("#ans").html(DataView);
    	    }
      
    });
    		}
    	</script>
        </body>
    </html>
    

    below is my two different tables stock and stock_orders

    save.png.520f880078a2cdd593e84c38b8e2b691.pngUntitled.thumb.png.4b389d2a9347cfdb5d1a7c4b95ac3c6c.png

  2. save.png.570d8a11818ca2f62377d5aecff4dcdb.pngUntitled.thumb.png.cd479c102ccc4d30130c7a6f4d3cc7e7.pngok sir can you help me edit my items i am still stuck here!!! 

    this is what ia was trying to do but cannot get my head around!!

    <?php 
    $con = new mysqli("localhost","root","","loginsystem");
    
    $errors = array();
    if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['updatestock'])):
    /*
    echo "<pre>";
    print_r($_POST);	 
    echo "</pre>";
    */
    	$fields = array(	
    		 "itemname" => "Item Name"
    	    ,"purchaseid" => "Purchase ID"	
    	    ,"poqty" => "Purchase Order QTY"
    	    
    	); 
    	
    	foreach($fields as $field => $label):
    		if(empty($_POST[$field])): 
    			array_push($errors,"Please Enter ".$label);
    		endif;
    	endforeach;
    	
    	//if(empty($errors)):
    		//$sqlpurchaseid = "SELECT `id` FROM `stock_orders` WHERE purchaseid = ? LIMIT 1"; 
    		//$querypurchaseid = $con->prepare($sqlpurchaseid);	
    		//$querypurchaseid->bind_param("i", $_POST['purchaseid']); 
    		//$querypurchaseid->execute(); 
    		//$resultpurchaseid = $querypurchaseid->get_result();	
    		//$rowpurchaseid = $resultpurchaseid->fetch_assoc();
    
    		//if(!empty($rowpurchaseid)){ 
    		//	array_push($errors,"This Purchase ID already exists");
    		//}
    	//endif;		
    	
    	
    	if(empty($errors)):	
    	
    		$today = date('Y-m-d');
    		
    		$sqlstockorder = "INSERT INTO `stock_orders`(`stock_id`, `purchaseid`, `poqty`, `entrydate`) 
    		VALUES (?,?,?,?)";
    		
    		$querystockorder = $con->prepare($sqlstockorder);		
    		$querystockorder->bind_param("iiis", $_POST['id'], $_POST['purchaseid'], $_POST['poqty'], $today); 		
    		$querystockorder->execute();
    	
    	
    		$sqlstock = "UPDATE `stock` SET 
    		`stockqty` =  ABS(COALESCE(stockqty,0)+?)		
    		WHERE `id` = ?";
    		$querystock = $con->prepare($sqlstock);		
    		$querystock->bind_param("ii", $_POST['poqty'], $_POST['id']); 		
    		$querystock->execute();
    		$num = $con -> affected_rows;			
    		$message = (!empty($num) ? "Stock Updated" : 'No Changes Made');	
    		
    		header("refresh: 3; URL=edit.php");
    	endif;
    	
    endif;
    
    $sql = "SELECT `itemname` FROM `stock`";
    $res = mysqli_query($con, $sql);
    ?>
    
    
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script type="text/javascript" src="fetch.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
        </head>
    <body>
    	
            
    <?php	
    
    if(!empty($message)):
    	echo '<div style="width:500px; text-align: center; margin:20px auto;">'."\r";
    		echo '<span style="color:green"><b>'.$message.'</b></span></br >'."\r";
    	echo '</div>'."\r";
    endif;
    if(!empty($errors)):
    	echo '<div style="width:500px; text-align: center; margin:20px auto;">'."\r";
    	foreach($errors as $error):
    		echo '<span style="color:red">'.$error.'</span></br >'."\r";
    	endforeach;
    	echo '</div>'."\r";
    endif;
    
    
    
    			
    if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['itemname'])){
    
    		echo '<form action="" method="post">
    			<table class="table table-bordered">
    				<thead class="table-primary" style="white-space:nowrap;">
    				<th>Stock ID</th>	 
    				<th>Item Name</th>
    				<th>Purchase ID</th>
    				<th>P.O. Quantity</th>				
    				<th>Update Stocks</th>
    				</thead>'."\r";	
    		
    			$sql = "select `id`, `itemname` from stock where itemname = ? "; 
    			$query = $con->prepare($sql);		
    			$query->bind_param("s",$_POST['itemname']); 		
    			$query->execute();
    			$result = $query->get_result();
    			while($rows = $result->fetch_assoc()){	
    			
    				$purchaseid = (!empty($_POST['purchaseid']) ? $_POST['purchaseid'] : '');
    				$poqty = (!empty($_POST['poqty']) ? $_POST['poqty'] : '');
    			
    				echo '<tr>
    					<td><input style="width:100%" type="text" name="id" value="'.$rows['id'].'" readonly /></td>
    					<td><input style="width:100%" type="text" name="itemname" value="'.$rows['itemname'].'" readonly /></td>
    					<td><input style="width:100%" type="text" name="purchaseid" value="'.$purchaseid.'" /></td>
    					<td><input style="width:100%" type="text" name="poqty" value="'.$poqty.'" /></td>					
    					<td><input style="width:100%" type="submit" name="updatestock" value="Update" /></td>
    				</tr>'."\r";
    			}
    		echo '</table>
    	</form>'."\r";
    	         
    }else{ 
    	echo '<b class="d-inline p-2 bg-primary text-white">Update Stock Here</b><hr>    
    	<b>Select Item to update :</b> 
        <select id="itemname" onchange="selectItem()">
            <option value="Select Item here" selected>Select Item here</option>'."\r";
    	
    		while ($rows = mysqli_fetch_array($res)){		 
    			echo '<option value="'.$rows['itemname'].'">'.$rows['itemname'].'</option>'."\r";
    		}
    		   
        echo '</select><br><br>'."\r";
    	echo '<div id="ans"></div>';
    }
    ?>
    	
    	<script type="text/javascript">
    		function selectItem(){
    			    var x = document.getElementById("itemname").value;
    			    
    			    $.ajax({
    			       url:"edit.php",
    			        method: "POST",
    			        data:{
    			            itemname : x
    			        },
    	        success:function(DataView){
    	        $("#ans").html(DataView);
    	    }
      
    });
    		}
    	</script>
        </body>
    </html>
    

    below are my two tables 

    save.png

     

  3. Sir getting confused what i have done wrong

     $query = mysqli_query($conn, "select ponum, status, itemname, SUM(stockqty) as total_qty from purchaseorder inner join stock on purchaseorder.id=stock.purchaseid group by itemname");
            
    <td><?php echo $row['ponum']?></td>
                    <td><?php echo $row['itemname']?></td>
                    <td><?php echo $row['0']?></td>
                    <td><?php echo $row['status']?></td>

    Below is the result 

    result.jpg

  4. no sir i want datas from both tables as well as the sum of stockqty from stock table!

    this is what i did.

     $query = mysqli_query($conn, "select *, SUM(stockqty) as total_qty from purchaseorder inner join stock on purchaseorder.id=stock.purchaseid order by itemname group by itemname");
            
      while($row=$query->fetch_array())
    			

    and it throws me an error Fatal error: Uncaught Error: Call to a member function fetch_array() on bool in C:\xampp\htdocs\Stock Manager updated today\Stock Manager\html\ltr\view.php:34 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Stock Manager updated today\Stock Manager\html\ltr\view.php on line 34

  5.  $query = mysqli_query($conn, "select SUM(stockqty),itemname,status,ponum from purchaseorder inner join stock on purchaseorder.id=stock.purchaseid group by ponum,stockqty,itemname,status ");

    Below is my stock table where i have purchaseid from purchaseorder table kindly help me how to fetch datas from both the tables and then retrieve sum of stockqty from stock table?

    Untitled.jpg

  6. // This is my actionpage.php
    <?php
    //session_start();
    //Checking User Logged or Not
    //if(empty($_SESSION['HR'])){
     //header('location:login.php');
    //}
    
        
    
    $host="127.0.0.1";
    $username="root";
    $pass="";
    $db="loginsystem";
    
    $conn=mysqli_connect($host,$username,$pass,$db);
    if(!$conn){
    	die("Database connection error");
    }
    
    
    
    if (isset($_POST["ronel"]))
        {
            $ponum = $_POST["ponum"];
            $podate = $_POST["podate"];
            $remarks = $_POST["remarks"];
            $status =  'stockin';
            $sql = "INSERT INTO purchaseorder(ponum, podate, remarks, status) VALUES ('$ponum','$podate','$remarks', '$status')";
            mysqli_query($conn, $sql);
            $purchaseid = mysqli_insert_id($conn);
     
            for ($a = 0; $a < count($_POST["itemname"]); $a++)
            {
                $sql = "INSERT INTO stock (purchaseid, itemname, poqty,unitno,entrydate,stockqty,deliver) VALUES ('$purchaseid', '" . $_POST["itemname"][$a] . "', '" . $_POST["poqty"][$a] . "','" . $_POST["unitno"][$a] . "','" . $_POST["entrydate"][$a] . "','" . $_POST["stockqty"][$a] . "','" . $_POST["deliver"][$a] . "')";
                mysqli_query($conn, $sql);
            }
     
            //echo "<p>Details has been added.</p>";
        	if(isset($_POST['ronel'])){
                header("location: insert.php");
            }
    	
        }
     
    ?>
    
    

    2. this is my form

                   <form action="actionpage.php" method="post" name="ronel">    
                            <div class="col-25"><label>1. P.O Number:*</label>
                            <input type="number" style="position:absolute; left:14.2%;" name="ponum" placeholder="P.O Number.."></div>
                            <br><div class="col-25"><label>2. P.O Date:*</label>     
                            <input style="position:absolute; left:14.2%;" type="date" name="podate"></div>
                            <br>
                            <div class="col-25"><label>3. Remarks:*</label>
                            <input type="text" style="position:relative; left:3%;" name="remarks" placeholder="Remarks.."></div>       
                            <input type="hidden"  name="status">
    <hr>
        <h5>4. Add rows to insert items</h5>
      <br/><table>
            <tr>
                <th>Sl</th>
                <th>Item Name</th>
                <th>P.O Quantity</th>
                <th>Unit No</th>
                <th>Entry date</th>
                <th>Stock Quantity</th>
                <th>Delivery Date</th>
                <th>Delete</th>
            </tr>
            <tbody id="tbody"></tbody>
        </table><br>    
        <button type="button" onclick="addItem();">Add Row</button>
        <input type="submit" name="ronel" value="Submit">
        </form>                 
    <script>
        var items = 0;
        function addItem() {
            items++;
     
            var html = "<tr>";
                html += "<td>" + items + "</td>";
            
                html += "<td><select name='itemname[]'> <option value='Pen'>Pen</option><option value='Paper Ream'>Paper Ream</option><option value='Bottle'>Bottle</option><option value='Calendar'>Calendar</option><option value='File'>File</option></select></td>";
                //html += "<td><input type='text'  style='width:120px;' name='itemname[]'></td>";
                html += "<td><input type='number' style='width:90px;' name='poqty[]'></td>";
                html += "<td><input type='number' style='width:90px;' name='unitno[]'></td>";
                html += "<td><input type='date' style='width:125px;' name='entrydate[]'></td>";
                html += "<td><input type='number' style='width:90px;' name='stockqty[]'></td>";
                html += "<td><input type='date' style='width:125px;' name='deliver[]'></td>";
                html += "<td><button type='button' onclick='deleteRow(this);'>Del Row</button></td>"
            html += "</tr>";
     
            var row = document.getElementById("tbody").insertRow();
            row.innerHTML = html;
        }
     
    function deleteRow(button) {
        button.parentElement.parentElement.remove();
        // first parentElement will be td and second will be tr.
    }
    </script>

    kindly help needed

  7. How do i update proposals with date and time when someone approves/complete/rejects the proposal? Screen123 is my database's image. Do i have to add a new column in it for date and time separately? 

    Down below screen12 is my dashboard image, in here i would like to add and show the time and date of the proposal after it gets approved/rejects/completed?

    1. This code here shows the approval index.

    <body>
       <?php
    session_start();
    //Checking User Logged or Not
    if(empty($_SESSION['user'])){
     header('location:index.php');
    }
    ?>
    <?php
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect("localhost","root", "","registration");
    
        $res = $conn->query("SELECT id
                                  , details      
                                  , location
                                  , date
                                  , time
                                  , reporteddept
                                  , reportedname
                                  , status                              
                              FROM proposals WHERE YEAR(date) = YEAR(CURDATE())
                              ORDER BY id    
                            ");
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-language" content="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
    <body>
        <h2 style="text-align:center; font-size:20px; inline-block; width: 180px; position: relative; left:40%; top:5px; font-weight: bold; background-color:#00FFFF; padding:6px;">DASHBOARD</h2>
    <div class="w3-content w3-padding">
    <style>
    table {
      font-family: arial, sans-serif;
      border-collapse: separate;
      width: 100%;
      table-layout: fixed;
       background-color: #EBFFE3;
       overflow: auto; 
       flex:1;
       text-overflow: ellipsis;}
    td, th {
      border: 1px solid #90D199;
      text-align: left;
      padding: 8px;
      text-overflow: ellipsis;  
      overflow: hidden;
      white-space: nowrap;}
    tr:nth-child(even) {
      background-color: #dddddd;
      text-overflow: ellipsis;}
    </style>  
    <table>
      <h3>
        <tr style="background-color:#E4EBC5; color:orangered;">
        <th>Nearmiss No.</th>
        <th>Details</th>  
        <th>Location</th>
        <th>Date</th>
        <th>Time</th>    
        <th>Status</th>   
      </tr>
        </h3>
        <?php
            if ($row = $res->fetch_assoc()) {
                do {
                    switch ($row['status']){}
                    echo "<tr>
                             <td><a href='plantapproval.php?id={$row['id']}' class='w3-button w3-tiny w3-khaki'>{$row['id']}{$row['reportedname']}{$row['reporteddept']}</a></td>
                             <td>{$row['details']}</td>             
                             <td>{$row['location']}</td>
                             <td>{$row['date']}</td>
                             <td>{$row['time']}</td>
                             <td>{$row['status']}</td>                                           
                          </tr>
                         ";
                } while ($row = $res->fetch_assoc());
            }
            else {
                echo "<tr><td>No records</td></tr>" ;
            }
        ?>    
        </table>
    </div>
    </body>
    </html>
     </body>  

    2. This code here is the approval.php and i want to add the date and time when the approval button gets clicked?

    <?php
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect("localhost","root", "","registration");
    
    //
    //   PROCESS POSTED DATA
    //
            if ($_SERVER['REQUEST_METHOD']=='POST') {
                $stmt = $conn->prepare("UPDATE proposals
                                        SET status = ?                                        
                                        WHERE id = ?
                                        ");
                $stmt->bind_param('si', $_POST['status'],$_POST['id']);
                $stmt->execute();
                
                header("Location: plantdashboard.php");
                exit;
            }
    if (!isset($_GET['id']) || trim($_GET['id'])=='') {
        header("Location: ");
        exit;
    }
    $res = $conn->prepare("SELECT id
                                , details
                                , location
                                , date
                                , time
                                , checkbox
                                , injured
                                , agegender
                                , contact
                                , empid
                                , dept
                                , organization
                                , summary
                                , image
                                , outcome
                                , cause
                                , action
                                , reportedname
                                , position
                                , organisation
                                , reportedcontact
                                , reporteddept
                                , status
                                
                                , department
                           FROM proposals
                           WHERE id = ?
                           ");
    $res->bind_param('i', $_GET['id']);
    $res->execute();
    $res->bind_result($id, $details, $location,  $date, $time, $checkbox,$injured,$agegender,$contact,$empid,$dept,$organization,$summary,$image,$outcome,$cause,$action,$reportedname,$position,$organisation,$reportedcontact,$reporteddept,$status,$department);
    $res->fetch();
    $res->close();
    //
    //  status-dependent processing
    //
    $buttons = "<div class='data'>
                <button name='status' class='w3-button w3-khaki' value='$status'>Update</button> 
                </div>";
    switch ($status)  {
        case 'pending':
            $cls1 = 'class="w3-dark-gray data"';
            $buttons = "<div class='data'>
                        <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;' class='w3-button w3-green' value='approved'>Approve</button> 
                        <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;' class='w3-button w3-red' value='rejected'>Reject</button>         
                        </div>
                        ";
            break;
        case 'approved':
            $cls1 = 'class="w3-pale-green data"';
            break;
        case 'rejected':
            $cls1 = 'class="w3-pale-red data"';    
    }
    $buttons1 = "<div class='data'>
                <button name='status' class='w3-button w3-khaki' value='$status'>Update</button> 
                </div>";
    switch ($status)  {
        case 'approved':
            $cls1 = 'class="w3-green data"';
            $buttons = "<div class='data'>
                <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;' value='completed' disabled>Complete</button> 
                </div>";
            break;
        case 'completed':
            $cls1 = 'class="w3-pale-green data"';
            $buttons = "<div class='data'>
                <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;'  value='$status' disabled>Update</button> 
                </div>";
        case 'rejected':
            $cls1 = 'class="w3-pale-green data"';
            $buttons = "<div class='data'>
                <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;'  value='$status' disabled>Update</button> 
                </div>";        
    }
    ?>
    
    <html lang = "en">
      <head>
        <title>Proposals</title>
        <meta charset = "UTF-8" />
      </head>
      <body><button onclick="myFunction()">Print</button>
    
    <script>
    function myFunction() {
      window.print();
    }
    </script>
        <h1>Proposal Form No : <?php echo $id ?></h1>
        <form method='POST' id='formId'>
        
        <input type='hidden' name='id' value='<?=$id?>'>
        
            <fieldset>
            <legend>NearMiss Proposal</legend>
            
              <p>
              <b style="font-size:17px; color:black; position: absolute; top:130px;">Details of incident :</b>
              <textarea style="position:relative;"  disabled id = "myTextArea"
                      rows = "5"
                      cols = "110"><?php echo $details ?></textarea></p><br>
            <fieldset style="height:55px; width:848px; border:1px solid #888;">
              <p>
              <b style="font-size:17px; color:black; position: relative; bottom:-5px;">Location :</b>
              <textarea style="position:absolute; left:115px;" disabled id = "myTextArea"
                     rows="2" cols="56"><?php echo $location ?></textarea>
            </p>
            <br>
              <p>
              <b style="font-size:17px; color:black; position:relative; left:545px; bottom:80px;" >Date :</b><textarea style="position:relative; left:555px; bottom:70px;" disabled id = "myTextArea"
                     rows="2" cols="10"><?php echo $date ?></textarea>
             
            </p>
              <p>
              <b style="font-size:17px; color:black; position:relative; left:708px; bottom:135px;" >Time :</b><textarea style="position:relative; left:715px; bottom:125px;" disabled id = "myTextArea"
                     rows="2" cols="10"><?php echo $time ?></textarea>        
            </p>
                </fieldset>
              <p><b>Classification(Tick the appropriate one, Leave blank if you find it difficulty) :</b><br>
              <label style="font-size:16px;color:black;">Selected Classification :</label>
              <textarea style="position:relative; bottom:-3px;" disabled id = "myTextArea"
                     rows="1" cols="47"><?php echo $checkbox ?></textarea>
            </p>
             <p>
              <b style="font-size:17px;color:black;">Details of Injured(IP)(if any) :NA</b><br>
                            <b>Name:</b>
                            
                                <textarea style="position:relative; bottom:-5px;" disabled name="name" cols="25" rows="1" class="form-control"> <?php echo $injured ?></textarea>
            </p>
            <p style="position:relative; left:280px; bottom:35px;">
               <b style="position:relative; bottom:4px;">Age/Gender :</b>
                            
                                <textarea disabled name="agegender" cols="3" rows="1"><?php echo $agegender ?></textarea>
              </p>
            <p style="position:relative; left:435px; bottom:75px;">
               <b style="position:relative; bottom:4px;">Contact :</b>
                            
                                <textarea disabled name="agegender" cols="9" rows="1"><?php echo $contact ?></textarea>
              </p>
            <p style="position:relative; left:600px; bottom:115px;">
               <b style="position:relative; bottom:4px;">Organization :</b>
                            
                                <textarea disabled name="agegender" cols="9" rows="1"><?php echo $organization ?></textarea>
              </p>
            <p style="position:relative; left:0px; bottom:125px;">
               <b style="position:relative; bottom:4px;">Department :</b>
                            
                                <textarea disabled name="agegender" cols="9" rows="1"><?php echo $dept ?></textarea>
              </p>
              <p style="position:relative; left:226px; bottom:165px;">
               <b style="position:relative; bottom:4px;">Employee ID :</b>
                            
                                <textarea disabled name="agegender" cols="9" rows="1"><?php echo $empid ?></textarea>
              </p><br>
            <p>
              <b style="color:black; position: relative; bottom:204px;">Summary of Incident(Attach Photographs, if any, as Annexure1) :</b>
              <textarea style="position:absolute; left:25px; top:525px;" disabled id = "myTextArea"
                     rows="8" cols="110"><?php echo $summary ?></textarea>
            </p>
            <div class="form-group">
                            <label style="position:absolute; left:82%; top:505px;">Uploaded Images Here :</label><b style="position:relative; left:88%; bottom:198px;"><?php echo "<a href='uploads/" . $image . "'><img src='uploads/" . $image . "'height='105' width='120'></a>" ?>  </b>
                            </div>
           
            <p>
              <b style="color:black; position: relative; bottom:186px;">Potential outcome(Incase of Near Miss Case or Potential incident only) :</b>
              <textarea style="position:absolute; left:27px; top:700px;" disabled id = "myTextArea"
                     rows="8" cols="110"><?php echo $outcome ?></textarea>     
              </p>
            <p>
              <b style="color:black; position: relative; bottom:146px;">Likely cause(s) :</b>
              <textarea style="position:relative; right:112px; top:-10px;" disabled id = "myTextArea"
                     rows="8" cols="110"><?php echo $cause ?></textarea>         
              </p><br>
            <p>
              <b style="position: absolute; top:1032px;">Immediate action(s) taken :</b>
              <textarea style=" float:left; position:relative; bottom:14px;" disabled id = "myTextArea"
                        rows="8" cols="110"><?php echo $action ?></textarea></p>
           <br><br><br><br><br><br><br>
              <p style="float:left;">
              <b style="font-size:17px;color:black;">Incident reported by :</b><br><br>
                            <b>Name:</b>
                            
                                <input type="text" disabled value="<?php echo $reportedname ?>">
                  <b>Position:</b>              
                  <input type="text" disabled value="<?php echo $position ?>">
                  <b>Organisation:</b>              
                  <input type="text" disabled value="<?php echo $organisation ?>"><br><br>
                  <b>Reporter contact no:</b>              
                  <input type="text" disabled value="<?php echo $reportedcontact ?>">
                  <b>Reporter department:</b>              
                  <input type="text" disabled name="name" value= "<?php echo $reporteddept ?>">
            </p>
          <fieldset style="position:relative; top:30px; width:848px; ">        
          <p>
              <b style="font-size:18px; color:darkblue;">Status of the Proposal : <div<?=$cls1?>><?=$status?></div></b>
                
            </p>
            <!--<p>
            <b style="font-size:18px;">Select Department :</b>    
            <input type='hidden' name='department'>
                    <tr>
        <td><select name='department'>
        <option value='' selected>------SELECT DEPARTMENT------</option>
        <option value='Civil'>Civil</option>
        <option value='O&M'>O&M</option>
        <option value='C&M'>C&M</option>
        <option value='MMD'>MMD</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>
            
      </select></td>
        </tr>
          </p>-->       
     
            
            <div>
                <b style="font-size:18px;">Selected Departments : <input type="text" disabled value="<?php echo $department ?>"></b>
                
            </div>
           </fieldset> 
           
            
         <br><br><br>
          </fieldset><br>
           <div style="display: flex; justify-content: center;">
            <?=$buttons?> 
        </div>
        </form> </body></html>
    <br>
    <label style="background-color:deepskyblue; border-radius: 5px; font-size:32px;">Uploaded Files after Completion</label>
      <fieldset style="background-color:aliceblue;">
    <br>
        <!--<div>
            <form action="upload.php" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" value="<?php echo $row->id?>"> 
                
                <div>
                     <label><b>Upload Image Here :</b></label><br><br>
                            <div>                            
                                <input type="file" name="name" enctype="multipart/form-data" id="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" width="220px" height="130px"></iframe><br><br>
                    <b>Details :</b><br>
        <div>
                    <textarea rows="6" cols="110" style="border-radius:12px;" name="details" placeholder="Details"></textarea>
        
            </div>
            </div>
                <input type="submit" name="submit" style="background-color:deepskyblue; cursor:pointer; border-radius: 8px; font-size:19px;" value="Submit"></form>
            
        </div>-->
         <?php
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect("localhost","root", "","registration");
    
    $res = $conn->prepare("SELECT id
                                ,image, details
                                FROM upload
                           WHERE id = ?
                           ");
    $res->bind_param('i', $_GET['id']);
    $res->execute();
    $res->bind_result($id,$image,$details);
               while ($res->fetch()) { 
        echo '<b style="font-size:18px;">Click Image to View</b><br><br>';       
        echo"<a href='completedupload/" . $image . "'><img src='completedupload/" . $image . "'height='105' width='120'></a><br><br>";  
        echo '<b style="font-size:18px;">Details :'.$details.'</b><br>';
      }          
    ?>
        </fieldset><br>
    <fieldset style="background-color:aliceblue;">
    <label style="background-color:deepskyblue; border-radius: 5px; font-size:22px;">Comment Section</label><br><br>
        <div>
            <form action="plantcomment.php" method="post">
            <input type="hidden" name="id" value="<?php echo $id ?>"> 
                
                <div>
                    <b>Name :</b>
                    <input type="text" name="cname" style="border-radius:5px;"><br><br>
                    <b>Leave a Comment :</b>
        <div>
                    <textarea rows="6" cols="110" style="border-radius:12px;" name="comment" placeholder="comment"></textarea>
        
            </div>
            </div>
                <input type="submit" name="postcomment" style="background-color:deepskyblue; cursor:pointer; border-radius: 8px; font-size:19px;" value="comment"></form>
            
    </div>
     <?php
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect("localhost","root", "","registration");
    
    if (!isset($_GET['id']) || trim($_GET['id'])=='') {
        header("Location: plantapproval.php ");
        exit;
    }
    
    $res = $conn->prepare("SELECT id
                                ,cname, comment,date
                                FROM comments
                           WHERE id = ?
                           ");
    $res->bind_param('i', $_GET['id']);
    $res->execute();
    $res->bind_result($id,$cname,$comment,$date);
               while ($res->fetch()) { 
               
        echo'<b style="color:darkmagenta">'.$cname.'  :  </b>';  
        echo ''.$comment.'<br>';
        echo'<b style="color:gray">'.$date.'</b><br><br>';
                 
      }
    
              
    ?>
    </fieldset>

    Kindly help me i am stuck. Thanks alot.

  8. Dear Sir/Madame

    I am trying to insert comments into a table called comments using echo ID in the input form but so far i can insert the comments with the post id but unable re-comment again kindly help me what do i do? 

    This is the input form:
    
     <div>
            <form action="ehscomment.php" method="post">
            <input type="hidden" name="id" value="<?php echo $id ?>"> 
                <div>
                    <label>Add comment</label>
        <div>
            <textarea rows="6" cols="110" name="comment" placeholder="comment"></textarea>
        
            </div>
            </div>
                <input type="submit" name="postcomment" value="comment"></form>
    </div> 

    And this is ehscomment.php

    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "registration";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
       die("Connection failed: " . $conn->connect_error);
    } 
    if(isset($_POST['postcomment'])){
           $id = $_POST['id'];
           $comment = $_POST['comment'];
           
    
    $sql = "INSERT INTO comments (id,comment)
    VALUES ('$id','$comment')";
    
    if ($conn->query($sql) === TRUE) {
       echo "New record created successfully";
    } else {
       echo "Error: " . $sql . "<br>" . $conn->error;
    }
    
    $conn->close();}
    ?>

    Error message: Error: INSERT INTO comments (id,comment) VALUES ('242','asddd')
    Duplicate entry '242' for key 'PRIMARY'

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.