473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once("connection/connection.php");
  3. ?>
  4. <?php $userid = $_GET['user']; ?>
  5. <html>
  6.  
  7.     <head>
  8.         <title>subok lang</title>
  9.         <link rel="stylesheet" type="text/css" href="css/sinusubok.css"/>
  10.         <script type="text/javascript" src="js/js-jquery-1.4.2.min.js"></script>
  11.         <script type="text/javascript">
  12.             $(document).ready(function () {
  13.                 var dt = $("#sumreport #currents").length;
  14.  
  15.  
  16.                 var dts = $("#sumreport #priors").length;
  17.  
  18.  
  19.                 alls = dt + dts;
  20.             if(alls>=8){
  21.                 alert("you have reach the verdict!");
  22.                 document.getElementById("btnadd").disabled = true;
  23.                 document.getElementById("btnadd1").disabled = true;
  24.             }
  25.  
  26.  
  27.  
  28.             });
  29.  
  30.             var numero;
  31.             var duplicate;
  32.             var sample = 1;
  33.             var inputtop = 10;
  34.             function addinput(){
  35.                 numero = document.createElement("input");
  36.                 duplicate = document.createElement("input");
  37.                 numero.setAttribute('name', 'obli1'+ sample);
  38.                 duplicate.setAttribute('name', "duplicate");
  39.                 numero.setAttribute('placeholder', 'Obligation_request'+ sample);
  40.                 numero.setAttribute('type', 'text');
  41.                 duplicate.setAttribute('type', 'hidden');
  42.                 duplicate.setAttribute('value', sample);
  43.                 numero.style.marginTop = inputtop + 'px';
  44.                 document.getElementById('obli').appendChild(numero);
  45.                 document.getElementById('obli').appendChild(duplicate);
  46.                 sample++;
  47.             }
  48.         </script>
  49.     </head>
  50.     <body>
  51.         <div id="wrapper">
  52.             <div id="side">
  53.                 <div id="current">
  54.                     <form name="frmcur" id="frmcur" method="post" action="">
  55.                     <input type="text" name="txtcred" id="txtcred" placeholder="Creditor"/><br/><br/>
  56.                     <div id="obli">
  57.                     <input type="text" name="txtobli" id="txtobli" placeholder="Obligation Request"/><button type="button"  onclick="addinput()">Add</button><br/><br/>
  58.                     </div>
  59.                     <select type="text" name="optobli" id="optobli">
  60.                         <option value="1">1 Personal Service</option>
  61.                         <option value="2">2 Financial Expenses</option>
  62.                     </select><br/><br/>
  63.                     <input type="text" name="txtgross" id="txtgross" placeholder="Gross Amount"/><br/><br/>
  64.                     <input type="text" name="txttax" id="txttax" placeholder="Withholding Tax"/><br/><br/>
  65.                     <button onclick = "counters()" type="submit" id="btnadd" name="btnadd">Add Creditor</button>
  66.                     <?php
  67.  
  68.  
  69.  
  70.                         if(!empty($_POST['frmcur'])){
  71.  
  72.                         }
  73.                         else{
  74.                         if(isset($_POST['btnadd'])){
  75.                             $credname = $_POST['txtcred'];
  76.                             $obli = $_POST['txtobli'];
  77.                             $opt1 = $_POST['optobli'];
  78.                             $gross = $_POST['txtgross'];
  79.                             $tax = $_POST['txttax'];
  80.                             $ctr = $_POST['duplicate'];
  81.  
  82.                         for($x=0;$x<$ctr;$x++){
  83.                             $thevalue = $_POST['obli1'+$x];
  84.                         }
  85.                             echo"<script>alert('$thevalue');</script>";
  86.                         if(empty($credname)|| empty($obli)|| empty($opt1)|| empty($gross)|| empty($tax)){
  87.  
  88.                         }
  89.  
  90.                         else{
  91.  
  92.                             $query1 = "INSERT INTO temp_current (user_id,credname,obli,allotment,gross,tax)
  93.                             VALUES ({$userid},'{$credname}','{$obli}','{$opt1}','{$gross}','{$tax}')";
  94.  
  95.                             mysql_query($query1,$connect);
  96.                             header("Location:sinusubok.php?user={$userid}");    
  97.  
  98.                         }
  99.                         }
  100.  
  101.  
  102.                         }
  103.  
  104.                     ?>
  105.                             </form>
  106.                 </div>
  107.  
  108.                 <div id="prior">
  109.  
  110. <form id="frmprior" name="frmprior" method="post" action="">
  111.                     <input type="text" name="txtcred1" id="txtcred1" placeholder="Creditor"/><br/><br/>
  112.                     <input type="text" name="txtobli1" id="txtobli1" placeholder="Obligation Request"/><br/><br/>
  113.                     <select type="text" name="optobli1" id="optobli1">
  114.                         <option value = "1">Personal Service</option>
  115.                         <option value = "2">Financial Expenses</option>
  116.                     </select><br/><br/>
  117.                     <input type="text" name="txtgross1" id="txtgross1" placeholder="Gross Amount"/><br/><br/>
  118.                     <input type="text" name="txttax1" id="txttax1" placeholder="Withholding Tax"/><br/><br/>
  119.                     <button  type="submit" id="btnadd1" name="btnadd1">Add Prior</button>
  120.                     <?php
  121.  
  122.  
  123.                         if(!empty($_POST['frmprior'])){
  124.  
  125.                         }
  126.                         else{
  127.                         if(isset($_POST['btnadd1'])){
  128.                             $credname1 = $_POST['txtcred1'];
  129.                             $obli1 = $_POST['txtobli1'];
  130.                             $opt11 = $_POST['optobli1'];
  131.                             $gross1 = $_POST['txtgross1'];
  132.                             $tax1 = $_POST['txttax1'];
  133.  
  134.  
  135.                             if(empty($credname1)||empty($obli1)||empty($opt11)||empty($gross1)||empty($tax1)){
  136.  
  137.                                 }
  138.                             else{
  139.                                 $query11 = "INSERT INTO temp_prior (user_id,credname,obli,allotment,gross,tax)
  140.                                 VALUES ({$userid},'{$credname1}','{$obli1}','{$opt11}','{$gross1}','{$tax1}')";
  141.                                 mysql_query($query11,$connect);
  142.                                 header("Location:sinusubok.php?user={$userid}");
  143.                             }
  144.                         }
  145.  
  146.                             }
  147.  
  148.  
  149.  
  150.                     ?>
  151.                     </form>
  152.             </div>
  153.             <div name="summary" id="summary">
  154.             <form id="frmrep" name="frmrep" method="post">
  155.                 <table id="sumreport" BORDER=2 CELLPADDING=4>
  156.                     <tr>
  157.                         <td colspan="8" style="text-align:center;" >Summary of Report</td>
  158.                     </tr>
  159.                     <tr>
  160.                         <td>Name</td>
  161.                         <td>Obligation Request</td>
  162.                         <td>Allotment Class</td>
  163.                         <td>Gross Amount</td>
  164.                         <td>Withholding Tax</td>
  165.                         <td>Net Amount</td>
  166.                         <td>Remarks</td>
  167.  
  168.                     </tr>
  169.                     <tr>
  170.                         <td colspan="8" style="text-align:center;">Current</td>
  171.                     </tr>
  172.  
  173.                     <?php
  174.                         $queryaccount = "SELECT * FROM temp_current";
  175.                                 $accounts = mysql_query($queryaccount,$connect);
  176.                                 $countaccount = mysql_num_rows($accounts);
  177.                             while($resultaccount = mysql_fetch_array($accounts))
  178.                             {
  179.  
  180.                                 $crdname = $resultaccount['credname'];
  181.                                 $oblit = $resultaccount['obli'];
  182.                                 $allot = $resultaccount['allotment'];
  183.                                 $grows = $resultaccount['gross'];
  184.                                 $taxes = $resultaccount['tax'];
  185.                                 $net = $grows-$taxes;
  186.  
  187.  
  188.                                 ?>    
  189.                                 <tr id="currents">
  190.                                     <td><?php echo $crdname;?></td>
  191.                                     <td><?php echo $oblit;?></td>
  192.                                     <td><?php echo $allot;?></td>
  193.                                     <td><?php echo $grows;?></td>
  194.                                     <td><?php echo $taxes;?></td>
  195.                                     <td><?php echo $net?></td>
  196.                                     <td></td>
  197.  
  198.                                 </tr>
  199.                                 <?php
  200.                                 }?>
  201.  
  202.                                 <tr>
  203.                                     <td colspan="8" style="text-align:center;">Prior</td>
  204.                                 </tr>
  205.  
  206.                                 <?php
  207.                         $queryaccount1 = "SELECT * FROM temp_prior";
  208.                                 $accounts1 = mysql_query($queryaccount1,$connect);
  209.                                 $countaccount1 = mysql_num_rows($accounts1);
  210.                             while($resultaccount1 = mysql_fetch_array($accounts1))
  211.                             {
  212.  
  213.                                 $crdname1 = $resultaccount1['credname'];
  214.                                 $oblit1 = $resultaccount1['obli'];
  215.                                 $allot1 = $resultaccount1['allotment'];
  216.                                 $grows1 = $resultaccount1['gross'];
  217.                                 $taxes1 = $resultaccount1['tax'];
  218.                                 $nets = $grows1-$taxes;
  219.  
  220.  
  221.                                 ?>    
  222.                                 <tr  id="priors">
  223.                                     <td><?php echo $crdname1;?></td>
  224.                                     <td><?php echo $oblit1;?></td>
  225.                                     <td><?php echo $allot1;?></td>
  226.                                     <td><?php echo $grows1;?></td>
  227.                                     <td><?php echo $taxes1;?></td>
  228.                                     <td><?php echo $nets?></td>
  229.                                     <td></td>
  230.                                 </tr>
  231.                                 <?php
  232.                                 }?>
  233.  
  234.                 </table>
  235.                 <button id="btngen" name="btngen" type="submit">Generate</button>
  236.                 <?php
  237.                 if(!empty($_POST['frmrep'])){
  238.                 }
  239.                 else{
  240.                     if(isset($_POST['btngen'])){
  241.                         header("Location:generate_report.php");
  242.                     }
  243.                 }
  244.                 ?>
  245.             </form>
  246.  
  247.             </div>
  248.         </div>
  249.     </body>
  250. </html>
Jul 23 '14 #1

✓ answered by Dormilich

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_exists(), or in case of GET/POST by using filter functions.

1 1387
Dormilich
8,658 Expert Mod 8TB
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_exists(), or in case of GET/POST by using filter functions.
Jul 23 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
6
by: nicy12 | last post by:
Hi! my name is Peter. iam working on the php platform. while trying to run and compile a program i get the undefined offset error iam nto much familiar with this error . Please help me . Thanks in...
9
by: simple12 | last post by:
Hello I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i...
2
by: neridaj | last post by:
Hello, I'm trying to figure out how to get rid of these errors: Notice: Undefined offset: 1 in output_fns.php on line 315 Notice: getimagesize() : Read error! in output_fns.php on line 315...
1
by: Mary meer | last post by:
i am trying to switch array value but i get this error message: Undefined offset 2 $at=array( array('Title:','title',2,10), array('First Name:','fname',2,10 ), ...
6
by: tbebest | last post by:
Hi , i have a form and it has A problem: i upload my 3 image and it uploaded in definded path but in insert in db filed there are empty: Notice: Undefined offset: 0 in C:\wamp\www Notice:...
4
by: Kevon | last post by:
Hello, I'm designing a photo gallery for my website, I've followed several tutorials online about how to go about doing this, with great success, I have come up with a set of codes, however I keep...
4
by: Vivek Sharan | last post by:
Hi, I'm getting this error "Undefined offset" for the lines $price=$match; $in_stock=$match; Below is the code. Please help me to solve this and also i need extract from website using php. Your...
1
by: Essiej | last post by:
Hi, I'm getting the error: undefined offset 1 on line 5 of cart.tpl and undefined offset 2 on line 6 of cart.tpl. The lines in this file are: 1 <?php 2
8
by: parul sinha | last post by:
whenever i am entering the quantity of item i got error undefined offset. i am sending my full code:- this is so.php for shopping cart:- <html> <center><table width="100%" height="300">...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.