how to update database through populated drop down menu in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kunal choudhary
    New Member
    • May 2013
    • 4

    how to update database through populated drop down menu in php

    I want to know how to update a database by editing of retrieval through populated drop down menu.after searching a lot it could not work.so please help me.

    Code:
    <?php
    while($row1 = @mysql_fetch_array($aCustomer,MYSQL_ASSOC))
    {
    echo "&nbsp;&nbsp;&nbsp;head &nbsp;<input type='text' name='head' value='".$row1['head']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;description &nbsp;<input type='text' name='description' value='".$row1['description']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;file no &nbsp;<input type='varchar' name='fileno' value='".$row1['fileno']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;Name of firm &nbsp;<input type='text' name='Nameoffirm' value='".$row1['Nameoffirm']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;exp &nbsp;<input type='int' name='exp' value='".$row1['exp']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;date of sanction &nbsp;<input type='date' name='dateofsanction' value='".$row1['dateofsanction']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;date of po &nbsp;<input type='date' name='dateofpo' value='".$row1['dateofpo']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;date of indent &nbsp;<input type='date' name='dateofindent' value='".$row1['dateofindent']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;bill no &nbsp;<input type='int' name='billno' value='".$row1['billno']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;date of bill no &nbsp;<input type='date' name='dateofbillno' value='".$row1['dateofbillno']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;BLno &nbsp;<input type='int' name='BLno' value='".$row1['BLno']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;bill pass &nbsp;<input type='varchar' name='billpass' value='".$row1['billpass']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;bill amount &nbsp;<input type='int' name='billamt' value='".$row1['billamt']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;date of bill &nbsp;<input type='date' name='dateofbill' value='".$row1['dateofbill']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;available bal &nbsp;<input type='int' name='availbal' value='".$row1['availbal']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;progressive bal &nbsp;<input type='int' name='progbal' value='".$row1['progbal']."'><br/><br/>";
    echo "&nbsp;&nbsp;&nbsp;remark &nbsp;<input type='varchar' name='remark' value='".$row1['remark']."'><br/><br/>";
    $head   = $row1['head'];
    $description = $row1['description'];
    $fileno   = $row1['fileno'];
    $Nameoffirm   = $row1['Nameoffirm'];
    $exp   = $row1['exp'];
    $dateofsanction   = $row1['dateofsanction'];
    $dateofpo  = $row1['dateofpo'];
    $indentno  = $row1['indentno'];
    $dateofindent   = $row1['dateofindent'];
    $billno   = $row1['billno'];
    $dateofbillno   = $row1['dateofbillno'];
    $BLno   = $row1['BLno'];
    $billpass   = $row1['billpass'];
    $billamt  = $row1['billamt'];
    $dateofbill   = $row1['dateofbill'];
    $availbal  = $row1['availbal'];
    $progbal   = $row1['progbal'];
    $remark   = $row1['remark'];
    
    ?>
    <?php } ?>
    
    
    </table>
    </td>
    </tr>
    <?php } ?>
    
    <form method="post">
    
    <?php
    if(isset($_POST['update']))
    {
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $dbname = "purchase";
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname) or die(mysql_error());
    if(! $conn )
    {
      die('Could not connect: ' . mysql_error());
    }
    $qry_result= mysql_query("SELECT RCtotal FROM nfcurrent") or die(mysql_error());
    $row=mysql_fetch_array($qry_result);
    $num=$row[RCtotal];
    
    $description2 = $_POST['description'];
    
    $fileno2=$_POST['fileno'];
    
    $indentno2 = $_POST['indentno'];
    
    $dateofindent2=$_POST['dateofindent'];
    
    $billno2 = $_POST['billno'];
    
    $dateofbillno=$_POST['dateofbillno'];;
    
    $BLno2 = $_POST['BLno'];
    $billpass2 = $_POST['billpass'];
    $billamt2 = $_POST['billamt'];
    $dateofbill2=$_POST['dateofbill'];
    
    $remark2 = $_POST['remark'];
    $availbal=$num;
    $progbal=$num-$billamt;
    
    $sql = "UPDATE nfone
           SET indentno ='$indentno2',
               dateofindent = '$dateofindent2',
               billno = '$billno2',
               dateofbillno = '$dateofbillno2',
               BLno = '$BLno2',
               billpass = '$billpass2',
               billamt = '$billamt2',
               dateofbill = '$dateofbill2',
    		   availbal = '$num',
    		   progbal = '$progbal'
               
         WHERE fileno = '$fileno'";
    
    	  
    mysql_select_db('purchase');
    $retval = mysql_query( $sql, $conn );
    $RC=$progbal;
    $sqla = "UPDATE nfcurrent
           SET RCtotal = '$progbal'";
    	   $retvala = mysql_query( $sqla);
    if(! $retval )
    {
      die('Could not update data: ' . mysql_error());
    }
    
    echo "Updated data successfully\n";
    
    mysql_close($conn);
    }
    else
    
    ?>
    <input name="update" type="submit" id="update" value="Update">
    </form>
    </table>
    </form>
    </body>
    </html>
Working...