edit data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lisles
    New Member
    • Jan 2010
    • 40

    edit data

    i need to edit data from the databse through a form.my code is below
    [code=php]
    <?php
    require_once "../inc/functions.php";
    require_once "../inc/vars.inc.php";
    sessionCheck();
    session_start() ;

    $old_sessionid = session_id(); //i've added these lines

    session_regener ate_id(); //i've added these lines

    $new_sessionid = session_id(); //i've added these lines
    ?>
    <?php include_once "admin_template s/case_header.php "; ?>

    <html>
    <head>
    <title>Untitl ed Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php
    $query="select * from designation where designation='Mi nister'";
    $exe=caseQuery( $query);
    if(mysql_num_ro ws($exe))
    {
    $output ='<table border="1">
    <tr><td>Name</td><td>Designat ion</td><td>Date of Appointment</td><td>Phone Office</td><td>Mobile</td><td>Residenc e</td><td>District </td><td>Taluka</td>
    <td>Panchayat Name</td><td>Panchaya t Address</td><td>Edit</td></tr>';
    $res=@mysql_fet ch_object($exe) ;
    $id=$res->sr_no;
    $output .='<tr><td>'.$r es->name.'</td><td>'.$res->designation. '</td><td>'.$res->dte.'</td><td>'.$res->ph_o.'</td><td>'.$res->ph_m.'</td><td>'.$res->ph_r.'</td><td>'.$res->district.'</td><td>'.$res->taluka.'</td><td>'.$res->pan_name.'</td><td>'.$res->pan_addr.'</td><td><a href="info.php? cmd=edit&id=$id ">Edit</a></td></tr>';

    }
    $output .= '</table>';
    echo "$output";

    ?>
    <?
    if($_GET["cmd"]=="edit")
    {
    $sql="select * from designation where designation='Mi nister'";
    $resl = caseQuery($sql) ;
    $result=mysql_f etch_array($res l);
    $name=$result["name"];
    $dsg=$result["designatio n"];
    $dt=$result["dte"];
    $ph_o=$result["ph_o"];
    $ph_m=$result["ph_m"];
    $ph_r=$result["ph_r"];
    $dis=$result["district"];
    $tal=$result["taluka"];
    $name=$result["pan_name"];
    $addr=$result["pan_addr"];
    }
    ?>

    </body>
    </html>

    [/code]

    on clicking edit a form should appear where i can edit the details.any idea how i can go about it?
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Do you know how to create HTML forms?




    Dan

    Comment

    • lisles
      New Member
      • Jan 2010
      • 40

      #3
      hey,i've worked on the code.managed to create he from on clicking edit.but after i edit and click the update button,the update doesnt take place.my code is below:
      [code=php]
      <?php
      require_once "../inc/functions.php";
      require_once "../inc/vars.inc.php";
      sessionCheck();
      session_start() ;

      $old_sessionid = session_id(); //i've added these lines

      session_regener ate_id(); //i've added these lines

      $new_sessionid = session_id(); //i've added these lines
      function getdsgType(){
      global $desig;
      $output = '<select name="dsgn" id="dsgn">';
      $output .= '<option value="">Design ation</option>';
      foreach($desig as $k=> $v){
      if($_POST['dsgn'] == $k){
      $output .= '<option value="'.$k.'" selected>'.$v.' </option>';
      }else{
      $output .= '<option value="'.$k.'"> '.$v.'</option>';
      }
      }
      $output .= '</select>';
      return $output;
      }
      ?>

      <?php include_once "admin_template s/case_header.php "; ?>

      <html>
      <head>
      <title>Untitl ed Document</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>

      <body>
      <?php
      $query="select * from designation where designation='Mi nister'";
      $exe=caseQuery( $query);
      if(mysql_num_ro ws($exe))
      {
      $output ='<table border="1">
      <tr><td>Name</td><td>Designat ion</td><td>Date of Appointment</td><td>Phone Office</td><td>Mobile</td><td>Residenc e</td><td>District </td><td>Taluka</td>
      <td>Panchayat Name</td><td>Panchaya t Address</td><td>Edit</td></tr>';
      $res=@mysql_fet ch_object($exe) ;
      $id=$res->sr_no;
      $output .='<tr><td>'.$r es->name.'</td><td>'.$res->designation. '</td><td>'.$res->dte.'</td><td>'.$res->ph_o.'</td><td>'.$res->ph_m.'</td><td>'.$res->ph_r.'</td><td>'.$res->district.'</td><td>'.$res->taluka.'</td><td>'.$res->pan_name.'</td><td>'.$res->pan_addr.'</td><td><a href="info.php? cmd=edit&id=$id ">Edit</a></td></tr>';

      }
      $output .= '</table>';
      echo "$output";

      ?>
      <?
      if($_GET["cmd"]=="edit")
      {
      $sql="select * from designation where designation='Mi nister'";
      $resl = caseQuery($sql) ;
      $result=mysql_f etch_array($res l);
      $id=$result["sr_no"];
      $name=$result["name"];
      $dsg=$result["designatio n"];
      $dt=$result["dte"];
      $ph_o=$result["ph_o"];
      $ph_m=$result["ph_m"];
      $ph_r=$result["ph_r"];

      echo "<form ENCTYPE=\"multi part/form-data\" action=\"".$_SE RVER['PHP_SELF']."\" method=\"post\" name=\"src_frm\ ">";
      echo "Sr_no:";
      echo "<input type=\"text\" value=\"".$resu lt["sr_no"]."\" maxlength=\"64\ " readonly name=\"id\" size=\"25\" /><br />";
      echo "<br/>";

      echo "Name:";
      echo "<input type=\"text\" value=\"".$resu lt["name"]."\" maxlength=\"64\ " name=\"name\" size=\"25\" /><br />";
      echo "<br/>";

      echo "Designatio n:";
      $query=caseQuer y("select designation from dsg");
      echo "<select name='dsgn' ><option value=''>Select one</option>";
      while($noticia = mysql_fetch_arr ay($query)) {
      echo "<option value='$noticia[designation]'>$noticia[designation]</option>";
      }
      echo "</select>";
      echo "<br/>";
      echo "<br/>";

      echo "Phone office:";
      echo "<input type=\"text\" value=\"".$resu lt["ph_o"]."\" maxlength=\"64\ " name=\"office\" size=\"25\" /><br />";
      echo "<br/>";

      echo "Mobile:";
      echo "<input type=\"text\" value=\"".$resu lt["ph_m"]."\" maxlength=\"64\ " name=\"mobile\" size=\"25\" /><br />";
      echo "<br/>";

      echo "Residence: ";
      echo "<input type=\"text\" value=\"".$resu lt["ph_r"]."\" maxlength=\"64\ " name=\"res\" size=\"25\" /><br />";
      echo "<br/>";
      echo "<button type=\"submit\" name=\"submit\" >Update</button>";
      echo "</form>";

      echo "PLEASE LEAVE THE MOBILE NUMBER AND RESIDENCE NUMBER FIELD BLANK IF THERE IS NO NUMBER.<br/>";


      if($_POST['submit']){
      $id=escape($_PO ST['id']);
      $name = escape($_POST['name']);
      $desg = escape($_POST['dsgn']);
      $ph_o= escape(trim($_P OST['office']));
      $ph_mob = escape($_POST['mobile']);
      $ph_res = escape($_POST['res']);
      echo "$id";
      $errCnt = 0;
      if(!$name)
      {
      $msg[] = "<h5>PLEASE ENTER A NAME</h5>";
      $errCnt++;
      }
      else
      if(!ctype_alpha ($name))
      {$msg[] = "<h5>YOU CAN ENTER ONLY ALPHABETS</h5>";
      $errCnt++;
      }


      if(!$desg)
      {
      $msg[] = "<h5>PLEASE SELECT A DESIGNATION</h5>";
      $errCnt++;;
      }


      if(!$ph_o)
      {
      $msg[] = "<h5>PLEASE ENTER THE OFFICE PHONE NUMBER</h5>";
      $errCnt++;
      }
      else
      if(!is_numeric( $ph_o))
      {
      $msg[] = "<h5>THE OFFICE PHONE NUMBER CAN ONLY HAVE NUMBERS</h5>";
      $errCnt++;
      }


      if(!$ph_mob)
      {
      $ph_mob="---- ";
      }
      else if(!is_numeric( $ph_mob))
      {
      $msg[] = "<h5>THE MOBILE NUMBER CAN ONLY HAVE NUMBERS</h5>";
      $errCnt++;
      }

      if(!$ph_res)
      {
      $ph_res="----";
      }
      else if(!is_numeric( $ph_res))
      {
      $msg[] = "<h5>THE RESIDENCE NUMBER CAN ONLY HAVE NUMBERS</h5>";
      $errCnt++;
      }

      $check="SELECT * FROM dsg, designation WHERE dsg.dsg_id BETWEEN 1 AND 7 AND designation.pan _name='".$vil_n ."'
      AND dsg.designation = designation.des ignation";
      $chk=caseQuery( $check);
      if(mysql_num_ro ws($chk))
      {
      $message= "you already have a entry for this panchayat";
      }

      if($errCnt == 0 && !message){
      $sql='UPDATE `designation` SET `name`="'.$name .'",`designatio n`="'.$desg.'", `ph_o`="'.$ph_o .'", `ph_m`="'.$ph_m ob.'",`ph_r`="' .$ph_res.'" WHERE sr_no="'.$id.'" ';

      $dist = caseInsertQuery ($sql);
      if($dist)
      {
      $ms= "<b>THE DATA HAS BEEN ADDED SUCCESFULLY</b>";
      }
      else
      {
      $ms= "<b>THE DATA COULD NOT BE ADDED</b>";
      }
      }
      else
      {
      $msgs = addslashes(@imp lode("<br>",$ms g));
      }
      }
      echo "$msgs";
      echo "$ms";
      echo "$message";
      }



      ?>

      </body>
      </html>

      [/code]

      Comment

      • lisles
        New Member
        • Jan 2010
        • 40

        #4
        i've changed my code a lil.but still having some problem.once i edit the data and click submit,nothing appens-the data doesnot get updated.my code is
        [code=php]
        <?php
        require_once "../inc/functions.php";
        require_once "../inc/vars.inc.php";
        sessionCheck();
        session_start() ;

        $old_sessionid = session_id(); //i've added these lines

        session_regener ate_id(); //i've added these lines

        $new_sessionid = session_id(); //i've added these lines
        function getdsgType(){
        global $desig;
        $output = '<select name="dsgn" id="dsgn">';
        $output .= '<option value="">Design ation</option>';
        foreach($desig as $k=> $v){
        if($_POST['dsgn'] == $k){
        $output .= '<option value="'.$k.'" selected>'.$v.' </option>';
        }else{
        $output .= '<option value="'.$k.'"> '.$v.'</option>';
        }
        }
        $output .= '</select>';
        return $output;
        }
        ?>

        <?php include_once "admin_template s/case_header.php "; ?>

        <html>
        <head>
        <title>Untitl ed Document</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>

        <body>
        <?php

        if(!isset($cmd) )
        {
        //display all the news
        $result = caseQuery("SELE CT *
        FROM dsg, designation
        WHERE dsg.dsg_id
        BETWEEN 1
        AND 7
        AND dsg.designation = designation.des ignation order by dsg.dsg_id");
        $rows=mysql_num _rows($result);
        if($rows)
        {
        echo "<div style='padding-left:20px;'><ta ble style='border-collapse:collap se; border-color:#000' border='1' cellspacing='0' cellpadding='5' width='400'>";
        echo "<tr><td width='150'>Id</td><td width='100'>Nam e</td><td width='60'>Desi gnation</td><td width='150'>Off ice</td><td width='150'>Mob ile</td><td width='150'>Res </td><td>Edit</td></tr>";
        for($i=1;$i<=$r ows;$i++) {
        $r=mysql_fetch_ array($result);
        $id=$r["sr_no"];
        echo "<tr><td>{$ r['sr_no']}</td><td>{$r['name']}</td><td>{$r['designation']}</td><td>{$r['ph_o']}</td><td>{$r['ph_m']}</td><td>{$r['ph_r']}</td><td><a href='edit.php? cmd=edit&id=$id '>Edit</a></td></tr>";
        echo "";
        }
        echo "</table></div>";
        }}
        ?>

        <?
        if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
        {
        if (!isset($_POST["submit"]))
        {
        $id = $_GET["id"];
        echo "$id";
        $sql = "SELECT * FROM designation WHERE sr_no=$id";
        $result = caseQuery($sql) ;
        $myrow = mysql_fetch_arr ay($result);
        ?>

        <form action="edit.ph p" method="post">
        <input type=hidden name="id" value="<?php echo $myrow["sr_no"] ?>">

        Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br>
        Designation:<?p hp
        $query=caseQuer y("select designation from dsg");
        echo "<select name='dsgn' ><option value=''>Select one</option>";
        while($noticia = mysql_fetch_arr ay($query)) {
        echo "<option value='$noticia[designation]'>$noticia[designation]</option>";
        }
        echo "</select>";
        ?><br>
        Phone Office:<INPUT TYPE="TEXT" NAME="ph_o" VALUE="<?php echo $myrow["ph_o"] ?>" SIZE=30><br>
        Phone Mobile:<INPUT TYPE="TEXT" NAME="ph_m" VALUE="<?php echo $myrow["ph_m"] ?>" SIZE=30><br>
        Phone Residence:<INPU T TYPE="TEXT" NAME="ph_r" VALUE="<?php echo $myrow["ph_r"] ?>" SIZE=30><br>
        <input type="hidden" name="cmd" value="edit">

        <input type="submit" name="submit" value="submit">

        </form>

        <? } ?>

        <?
        if ($_POST["$submit"])
        {
        $name = $_POST["name"];
        $dsgn = $_POST["dsgn"];
        $ph_o = $_POST["ph_o"];
        $ph_m = $_POST["ph_m"];
        $ph_r = $_POST["ph_r"];
        $id=$_POST["id"];
        $sql = "UPDATE designation SET name='$name',de signation='$dsg n',ph_o='$ph_o' ,ph_m='$ph_m',p h_r='$ph_r' WHERE sr_no=$id";

        $result = caseQuery($sql) ;
        if($result)
        {
        echo "Thank you! Information updated.";
        }
        else
        {
        echo "cannot update your data";
        }
        }
        }
        ?>


        </body>
        </html>

        [/code]

        please please help me some one.i need the code urgently

        Comment

        Working...