how to fix undefined offset while getting the value of a duplicated code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eugene24
    New Member
    • Jul 2014
    • 1

    #1

    how to fix undefined offset while getting the value of a duplicated code?

    Code:
    <?php
    require_once("connection/connection.php");
    ?>
    <?php $userid = $_GET['user']; ?>
    <html>
    
    	<head>
    		<title>subok lang</title>
    		<link rel="stylesheet" type="text/css" href="css/sinusubok.css"/>
    		<script type="text/javascript" src="js/js-jquery-1.4.2.min.js"></script>
    		<script type="text/javascript">
    			$(document).ready(function () {
    				var dt = $("#sumreport #currents").length;
    				
    				
    				var dts = $("#sumreport #priors").length;
    				
    				
    				alls = dt + dts;
    			if(alls>=8){
    				alert("you have reach the verdict!");
    				document.getElementById("btnadd").disabled = true;
    				document.getElementById("btnadd1").disabled = true;
    			}
    			
    			
    			
    			});
    			
    			var numero;
    			var duplicate;
    			var sample = 1;
    			var inputtop = 10;
    			function addinput(){
    				numero = document.createElement("input");
    				duplicate = document.createElement("input");
    				numero.setAttribute('name', 'obli1'+ sample);
    				duplicate.setAttribute('name', "duplicate");
    				numero.setAttribute('placeholder', 'Obligation_request'+ sample);
    				numero.setAttribute('type', 'text');
    				duplicate.setAttribute('type', 'hidden');
    				duplicate.setAttribute('value', sample);
    				numero.style.marginTop = inputtop + 'px';
    				document.getElementById('obli').appendChild(numero);
    				document.getElementById('obli').appendChild(duplicate);
    				sample++;
    			}
    		</script>
    	</head>
    	<body>
    		<div id="wrapper">
    			<div id="side">
    				<div id="current">
    					<form name="frmcur" id="frmcur" method="post" action="">
    					<input type="text" name="txtcred" id="txtcred" placeholder="Creditor"/><br/><br/>
    					<div id="obli">
    					<input type="text" name="txtobli" id="txtobli" placeholder="Obligation Request"/><button type="button"  onclick="addinput()">Add</button><br/><br/>
    					</div>
    					<select type="text" name="optobli" id="optobli">
    						<option value="1">1 Personal Service</option>
    						<option value="2">2 Financial Expenses</option>
    					</select><br/><br/>
    					<input type="text" name="txtgross" id="txtgross" placeholder="Gross Amount"/><br/><br/>
    					<input type="text" name="txttax" id="txttax" placeholder="Withholding Tax"/><br/><br/>
    					<button onclick = "counters()" type="submit" id="btnadd" name="btnadd">Add Creditor</button>
    					<?php
    
    			
    
    						if(!empty($_POST['frmcur'])){
    								
    						}
    						else{
    						if(isset($_POST['btnadd'])){
    							$credname = $_POST['txtcred'];
    							$obli = $_POST['txtobli'];
    							$opt1 = $_POST['optobli'];
    							$gross = $_POST['txtgross'];
    							$tax = $_POST['txttax'];
    							$ctr = $_POST['duplicate'];
    							
    						for($x=0;$x<$ctr;$x++){
    							$thevalue = $_POST['obli1'+$x];
    						}
    							echo"<script>alert('$thevalue');</script>";
    						if(empty($credname)|| empty($obli)|| empty($opt1)|| empty($gross)|| empty($tax)){
    							
    						}
    						
    						else{
    							
    							$query1 = "INSERT INTO temp_current (user_id,credname,obli,allotment,gross,tax)
    							VALUES ({$userid},'{$credname}','{$obli}','{$opt1}','{$gross}','{$tax}')";
    							
    							mysql_query($query1,$connect);
    							header("Location:sinusubok.php?user={$userid}");	
    							
    						}
    						}
    						
    						
    						}
    						
    					?>
    							</form>
    				</div>
    			
    				<div id="prior">
    					
    <form id="frmprior" name="frmprior" method="post" action="">
    					<input type="text" name="txtcred1" id="txtcred1" placeholder="Creditor"/><br/><br/>
    					<input type="text" name="txtobli1" id="txtobli1" placeholder="Obligation Request"/><br/><br/>
    					<select type="text" name="optobli1" id="optobli1">
    						<option value = "1">Personal Service</option>
    						<option value = "2">Financial Expenses</option>
    					</select><br/><br/>
    					<input type="text" name="txtgross1" id="txtgross1" placeholder="Gross Amount"/><br/><br/>
    					<input type="text" name="txttax1" id="txttax1" placeholder="Withholding Tax"/><br/><br/>
    					<button  type="submit" id="btnadd1" name="btnadd1">Add Prior</button>
    					<?php
    					
    
    						if(!empty($_POST['frmprior'])){
    						
    						}
    						else{
    						if(isset($_POST['btnadd1'])){
    							$credname1 = $_POST['txtcred1'];
    							$obli1 = $_POST['txtobli1'];
    							$opt11 = $_POST['optobli1'];
    							$gross1 = $_POST['txtgross1'];
    							$tax1 = $_POST['txttax1'];
    							
    							
    							if(empty($credname1)||empty($obli1)||empty($opt11)||empty($gross1)||empty($tax1)){
    								
    								}
    							else{
    								$query11 = "INSERT INTO temp_prior (user_id,credname,obli,allotment,gross,tax)
    								VALUES ({$userid},'{$credname1}','{$obli1}','{$opt11}','{$gross1}','{$tax1}')";
    								mysql_query($query11,$connect);
    								header("Location:sinusubok.php?user={$userid}");
    							}
    						}
    						
    							}
    							
    						
    						
    					?>
    					</form>
    			</div>
    			<div name="summary" id="summary">
    			<form id="frmrep" name="frmrep" method="post">
    				<table id="sumreport" BORDER=2 CELLPADDING=4>
    					<tr>
    						<td colspan="8" style="text-align:center;" >Summary of Report</td>
    					</tr>
    					<tr>
    						<td>Name</td>
    						<td>Obligation Request</td>
    						<td>Allotment Class</td>
    						<td>Gross Amount</td>
    						<td>Withholding Tax</td>
    						<td>Net Amount</td>
    						<td>Remarks</td>
    						
    					</tr>
    					<tr>
    						<td colspan="8" style="text-align:center;">Current</td>
    					</tr>
    								
    					<?php
    						$queryaccount = "SELECT * FROM temp_current";
    								$accounts = mysql_query($queryaccount,$connect);
    								$countaccount = mysql_num_rows($accounts);
    							while($resultaccount = mysql_fetch_array($accounts))
    							{
    								
    								$crdname = $resultaccount['credname'];
    								$oblit = $resultaccount['obli'];
    								$allot = $resultaccount['allotment'];
    								$grows = $resultaccount['gross'];
    								$taxes = $resultaccount['tax'];
    								$net = $grows-$taxes;
    								
    								
    								?>	
    								<tr id="currents">
    									<td><?php echo $crdname;?></td>
    									<td><?php echo $oblit;?></td>
    									<td><?php echo $allot;?></td>
    									<td><?php echo $grows;?></td>
    									<td><?php echo $taxes;?></td>
    									<td><?php echo $net?></td>
    									<td></td>
    									
    								</tr>
    								<?php
    								}?>
    								
    								<tr>
    									<td colspan="8" style="text-align:center;">Prior</td>
    								</tr>
    								
    								<?php
    						$queryaccount1 = "SELECT * FROM temp_prior";
    								$accounts1 = mysql_query($queryaccount1,$connect);
    								$countaccount1 = mysql_num_rows($accounts1);
    							while($resultaccount1 = mysql_fetch_array($accounts1))
    							{
    								
    								$crdname1 = $resultaccount1['credname'];
    								$oblit1 = $resultaccount1['obli'];
    								$allot1 = $resultaccount1['allotment'];
    								$grows1 = $resultaccount1['gross'];
    								$taxes1 = $resultaccount1['tax'];
    								$nets = $grows1-$taxes;
    								
    								
    								?>	
    								<tr  id="priors">
    									<td><?php echo $crdname1;?></td>
    									<td><?php echo $oblit1;?></td>
    									<td><?php echo $allot1;?></td>
    									<td><?php echo $grows1;?></td>
    									<td><?php echo $taxes1;?></td>
    									<td><?php echo $nets?></td>
    									<td></td>
    								</tr>
    								<?php
    								}?>
    								
    				</table>
    				<button id="btngen" name="btngen" type="submit">Generate</button>
    				<?php
    				if(!empty($_POST['frmrep'])){
    				}
    				else{
    					if(isset($_POST['btngen'])){
    						header("Location:generate_report.php");
    					}
    				}
    				?>
    			</form>
    				
    			</div>
    		</div>
    	</body>
    </html>
    Last edited by Dormilich; Jul 23 '14, 09:09 AM. Reason: please use code tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you cannot "fix" an undefined offset, you can only make sure that you don’t call an offset that doesn’t exist, e.g. by testing with isset() or array_key_exist s(), or in case of GET/POST by using filter functions.

    Comment

    Working...