473,811 Members | 3,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

edit data

40 New Member
i need to edit data from the databse through a form.my code is below
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once "../inc/functions.php";
  3. require_once "../inc/vars.inc.php";
  4. sessionCheck();
  5. session_start();
  6.  
  7. $old_sessionid = session_id(); //i've added these lines
  8.  
  9. session_regenerate_id(); //i've added these lines
  10.  
  11. $new_sessionid = session_id(); //i've added these lines
  12. ?>
  13. <?php include_once "admin_templates/case_header.php"; ?>
  14.  
  15. <html>
  16. <head>
  17. <title>Untitled Document</title>
  18. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  19. </head>
  20.  
  21. <body>
  22. <?php
  23. $query="select * from designation where designation='Minister'";
  24. $exe=caseQuery($query);
  25. if(mysql_num_rows($exe))
  26. {
  27. $output ='<table  border="1">
  28. <tr><td>Name</td><td>Designation</td><td>Date of Appointment</td><td>Phone Office</td><td>Mobile</td><td>Residence</td><td>District</td><td>Taluka</td>
  29. <td>Panchayat Name</td><td>Panchayat Address</td><td>Edit</td></tr>';
  30. $res=@mysql_fetch_object($exe);
  31. $id=$res->sr_no;
  32. $output .='<tr><td>'.$res->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>';
  33.  
  34. }
  35. $output .= '</table>';
  36. echo "$output";
  37.  
  38. ?>
  39. <?
  40. if($_GET["cmd"]=="edit")
  41. {
  42. $sql="select * from designation where designation='Minister'";
  43.     $resl = caseQuery($sql);
  44.     $result=mysql_fetch_array($resl);
  45.     $name=$result["name"];
  46.     $dsg=$result["designation"];
  47.     $dt=$result["dte"];
  48.     $ph_o=$result["ph_o"];
  49.     $ph_m=$result["ph_m"];
  50.     $ph_r=$result["ph_r"];
  51.     $dis=$result["district"];
  52.     $tal=$result["taluka"];
  53.     $name=$result["pan_name"];
  54.     $addr=$result["pan_addr"];
  55.      }
  56. ?>
  57.  
  58. </body>
  59. </html>
  60.  
  61.  
on clicking edit a form should appear where i can edit the details.any idea how i can go about it?
Feb 22 '10 #1
3 2695
dlite922
1,584 Recognized Expert Top Contributor
Do you know how to create HTML forms?




Dan
Feb 22 '10 #2
lisles
40 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once "../inc/functions.php";
  3. require_once "../inc/vars.inc.php";
  4. sessionCheck();
  5. session_start();
  6.  
  7. $old_sessionid = session_id(); //i've added these lines
  8.  
  9. session_regenerate_id(); //i've added these lines
  10.  
  11. $new_sessionid = session_id(); //i've added these lines
  12. function getdsgType(){
  13.     global $desig;
  14.     $output = '<select name="dsgn" id="dsgn">';
  15.     $output .= '<option value="">Designation</option>';    
  16.     foreach($desig as $k=> $v){
  17.         if($_POST['dsgn'] == $k){
  18.             $output .= '<option value="'.$k.'" selected>'.$v.'</option>';
  19.         }else{
  20.             $output .= '<option value="'.$k.'">'.$v.'</option>';        
  21.         }
  22.     }
  23.     $output .= '</select>';
  24.     return $output;
  25. }
  26. ?>
  27.  
  28. <?php include_once "admin_templates/case_header.php"; ?>
  29.  
  30. <html>
  31. <head>
  32. <title>Untitled Document</title>
  33. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  34. </head>
  35.  
  36. <body>
  37. <?php
  38. $query="select * from designation where designation='Minister'";
  39. $exe=caseQuery($query);
  40. if(mysql_num_rows($exe))
  41. {
  42. $output ='<table  border="1">
  43. <tr><td>Name</td><td>Designation</td><td>Date of Appointment</td><td>Phone Office</td><td>Mobile</td><td>Residence</td><td>District</td><td>Taluka</td>
  44. <td>Panchayat Name</td><td>Panchayat Address</td><td>Edit</td></tr>';
  45. $res=@mysql_fetch_object($exe);
  46. $id=$res->sr_no;
  47. $output .='<tr><td>'.$res->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>';
  48.  
  49. }
  50. $output .= '</table>';
  51. echo "$output";
  52.  
  53. ?>
  54. <?
  55. if($_GET["cmd"]=="edit")
  56. {
  57. $sql="select * from designation where designation='Minister'";
  58.     $resl = caseQuery($sql);
  59.     $result=mysql_fetch_array($resl);
  60.     $id=$result["sr_no"];
  61.     $name=$result["name"];
  62.     $dsg=$result["designation"];
  63.     $dt=$result["dte"];
  64.     $ph_o=$result["ph_o"];
  65.     $ph_m=$result["ph_m"];
  66.     $ph_r=$result["ph_r"];
  67.  
  68.     echo "<form ENCTYPE=\"multipart/form-data\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" name=\"src_frm\">";
  69.     echo "Sr_no:";
  70.     echo "<input type=\"text\" value=\"".$result["sr_no"]."\" maxlength=\"64\" readonly name=\"id\" size=\"25\" /><br />";
  71.     echo "<br/>";
  72.  
  73.     echo "Name:";
  74.     echo "<input type=\"text\" value=\"".$result["name"]."\" maxlength=\"64\" name=\"name\" size=\"25\" /><br />";
  75.     echo "<br/>";
  76.  
  77.     echo "Designation:";
  78.     $query=caseQuery("select designation from dsg");
  79.     echo "<select name='dsgn' ><option value=''>Select one</option>";
  80.     while($noticia = mysql_fetch_array($query)) { 
  81.     echo  "<option value='$noticia[designation]'>$noticia[designation]</option>";
  82.      }
  83.     echo "</select>";
  84.     echo "<br/>";
  85.     echo "<br/>";
  86.  
  87.     echo "Phone office:";
  88.     echo "<input type=\"text\" value=\"".$result["ph_o"]."\" maxlength=\"64\" name=\"office\" size=\"25\" /><br />";
  89.     echo "<br/>";
  90.  
  91.     echo "Mobile:";
  92.     echo "<input type=\"text\" value=\"".$result["ph_m"]."\" maxlength=\"64\" name=\"mobile\" size=\"25\" /><br />";
  93.     echo "<br/>";
  94.  
  95.     echo "Residence:";
  96.     echo "<input type=\"text\" value=\"".$result["ph_r"]."\" maxlength=\"64\" name=\"res\" size=\"25\" /><br />";
  97.     echo "<br/>";
  98.     echo "<button type=\"submit\" name=\"submit\">Update</button>";
  99.     echo "</form>";
  100.  
  101.     echo "PLEASE LEAVE THE MOBILE NUMBER AND RESIDENCE NUMBER FIELD BLANK IF THERE IS NO NUMBER.<br/>";
  102.  
  103.  
  104.     if($_POST['submit']){
  105.     $id=escape($_POST['id']);
  106.     $name = escape($_POST['name']);
  107.     $desg = escape($_POST['dsgn']);    
  108.     $ph_o= escape(trim($_POST['office']));
  109.     $ph_mob = escape($_POST['mobile']);
  110.     $ph_res = escape($_POST['res']);
  111.     echo "$id";
  112.     $errCnt = 0;
  113.     if(!$name)
  114.     {
  115.     $msg[] = "<h5>PLEASE ENTER A NAME</h5>";
  116.     $errCnt++;
  117.     }
  118.     else
  119.     if(!ctype_alpha($name))
  120.     {$msg[] = "<h5>YOU CAN ENTER ONLY ALPHABETS</h5>";
  121.     $errCnt++;
  122.     }
  123.  
  124.  
  125.     if(!$desg)
  126.     {
  127.     $msg[] = "<h5>PLEASE SELECT A DESIGNATION</h5>";
  128.     $errCnt++;;
  129.     }
  130.  
  131.  
  132.     if(!$ph_o)
  133.     {
  134.     $msg[] = "<h5>PLEASE ENTER THE OFFICE PHONE NUMBER</h5>";
  135.     $errCnt++;
  136.     }
  137.     else
  138.     if(!is_numeric($ph_o))
  139.     {
  140.     $msg[] = "<h5>THE OFFICE PHONE NUMBER CAN ONLY HAVE NUMBERS</h5>";
  141.     $errCnt++;
  142.     }
  143.  
  144.  
  145.     if(!$ph_mob)
  146.     {
  147.     $ph_mob="---- ";
  148.     }
  149.     else if(!is_numeric($ph_mob))
  150.     {
  151.     $msg[] = "<h5>THE MOBILE NUMBER CAN ONLY HAVE NUMBERS</h5>";
  152.     $errCnt++;
  153.     }
  154.  
  155.     if(!$ph_res)
  156.     {
  157.     $ph_res="----";
  158.     }
  159.     else if(!is_numeric($ph_res))
  160.     {
  161.     $msg[] = "<h5>THE RESIDENCE NUMBER CAN ONLY HAVE NUMBERS</h5>";
  162.     $errCnt++;
  163.     }
  164.  
  165.     $check="SELECT * FROM dsg, designation WHERE dsg.dsg_id BETWEEN 1 AND 7 AND designation.pan_name='".$vil_n."'
  166.      AND dsg.designation = designation.designation";
  167.     $chk=caseQuery($check);
  168.     if(mysql_num_rows($chk))
  169.     {
  170.     $message= "you already have a entry for this panchayat";
  171.     }
  172.  
  173.     if($errCnt == 0 && !message){
  174.     $sql='UPDATE `designation` SET  `name`="'.$name.'",`designation`="'.$desg.'",`ph_o`="'.$ph_o.'", `ph_m`="'.$ph_mob.'",`ph_r`="'.$ph_res.'" WHERE sr_no="'.$id.'"';
  175.  
  176.             $dist = caseInsertQuery($sql);
  177.             if($dist)
  178.             {
  179.             $ms= "<b>THE DATA HAS BEEN ADDED SUCCESFULLY</b>";
  180.             }
  181.             else
  182.             {
  183.             $ms= "<b>THE DATA COULD NOT BE ADDED</b>";
  184.             }
  185.             }
  186.             else
  187.             {
  188.             $msgs = addslashes(@implode("<br>",$msg));
  189.             }
  190.     }
  191. echo "$msgs";
  192. echo "$ms";
  193. echo "$message";
  194.      }
  195.  
  196.  
  197.  
  198. ?>
  199.  
  200. </body>
  201. </html>
  202.  
  203.  
Feb 23 '10 #3
lisles
40 New Member
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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once "../inc/functions.php";
  3. require_once "../inc/vars.inc.php";
  4. sessionCheck();
  5. session_start();
  6.  
  7. $old_sessionid = session_id(); //i've added these lines
  8.  
  9. session_regenerate_id(); //i've added these lines
  10.  
  11. $new_sessionid = session_id(); //i've added these lines
  12. function getdsgType(){
  13.     global $desig;
  14.     $output = '<select name="dsgn" id="dsgn">';
  15.     $output .= '<option value="">Designation</option>';    
  16.     foreach($desig as $k=> $v){
  17.         if($_POST['dsgn'] == $k){
  18.             $output .= '<option value="'.$k.'" selected>'.$v.'</option>';
  19.         }else{
  20.             $output .= '<option value="'.$k.'">'.$v.'</option>';        
  21.         }
  22.     }
  23.     $output .= '</select>';
  24.     return $output;
  25. }
  26. ?>
  27.  
  28. <?php include_once "admin_templates/case_header.php"; ?>
  29.  
  30. <html>
  31. <head>
  32. <title>Untitled Document</title>
  33. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  34. </head>
  35.  
  36. <body>
  37. <?php
  38.  
  39. if(!isset($cmd)) 
  40. {
  41.    //display all the news
  42.    $result = caseQuery("SELECT * 
  43. FROM dsg, designation
  44. WHERE dsg.dsg_id
  45. BETWEEN 1 
  46. AND 7 
  47. AND dsg.designation = designation.designation order by dsg.dsg_id"); 
  48.    $rows=mysql_num_rows($result);
  49.    if($rows)
  50. {
  51. echo "<div style='padding-left:20px;'><table style='border-collapse:collapse; border-color:#000' border='1' cellspacing='0' cellpadding='5' width='400'>";
  52.         echo "<tr><td width='150'>Id</td><td width='100'>Name</td><td width='60'>Designation</td><td width='150'>Office</td><td width='150'>Mobile</td><td width='150'>Res</td><td>Edit</td></tr>";
  53.         for($i=1;$i<=$rows;$i++) {
  54.             $r=mysql_fetch_array($result); 
  55.         $id=$r["sr_no"];
  56. 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>";
  57.         echo "";
  58.         }
  59.         echo "</table></div>";
  60. }}
  61. ?>
  62.  
  63. <?
  64. if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
  65. {
  66.    if (!isset($_POST["submit"]))
  67.    {
  68.       $id = $_GET["id"];
  69.       echo "$id";
  70.       $sql = "SELECT * FROM  designation WHERE sr_no=$id";
  71.       $result = caseQuery($sql);        
  72.       $myrow = mysql_fetch_array($result);
  73.       ?>
  74.  
  75.       <form action="edit.php" method="post">
  76.       <input type=hidden name="id" value="<?php echo $myrow["sr_no"] ?>">
  77.  
  78.       Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br>
  79.       Designation:<?php
  80.   $query=caseQuery("select designation from dsg");
  81. echo "<select name='dsgn' ><option value=''>Select one</option>";
  82. while($noticia = mysql_fetch_array($query)) { 
  83. echo  "<option value='$noticia[designation]'>$noticia[designation]</option>";
  84. }
  85. echo "</select>";
  86. ?><br>
  87.      Phone Office:<INPUT TYPE="TEXT" NAME="ph_o" VALUE="<?php echo $myrow["ph_o"] ?>" SIZE=30><br>
  88.     Phone Mobile:<INPUT TYPE="TEXT" NAME="ph_m" VALUE="<?php echo $myrow["ph_m"] ?>" SIZE=30><br>
  89.      Phone Residence:<INPUT TYPE="TEXT" NAME="ph_r" VALUE="<?php echo $myrow["ph_r"] ?>" SIZE=30><br>
  90.       <input type="hidden" name="cmd" value="edit">
  91.  
  92.       <input type="submit" name="submit" value="submit">
  93.  
  94.       </form>
  95.  
  96.    <? } ?>
  97.  
  98.    <?
  99.    if ($_POST["$submit"])
  100.    {
  101.       $name = $_POST["name"];
  102.       $dsgn = $_POST["dsgn"];
  103.       $ph_o = $_POST["ph_o"];
  104.       $ph_m = $_POST["ph_m"];
  105.       $ph_r = $_POST["ph_r"];
  106.       $id=$_POST["id"];
  107.       $sql = "UPDATE designation SET name='$name',designation='$dsgn',ph_o='$ph_o',ph_m='$ph_m',ph_r='$ph_r' WHERE sr_no=$id";
  108.  
  109.       $result = caseQuery($sql);
  110.       if($result)
  111.       {
  112.       echo "Thank you! Information updated.";
  113.       }
  114.       else
  115.       {
  116.       echo "cannot update your data";
  117.       }
  118.    }
  119. }
  120. ?>
  121.  
  122.  
  123. </body>
  124. </html>
  125.  
  126.  
please please help me some one.i need the code urgently
Feb 23 '10 #4

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

Similar topics

10
2051
by: Jim | last post by:
Hi, Let me explain how I'd generally do things. For a page where the user edits data, I'd generally call it something like editfred.php (for example), the page which updates the data would be called updatefred.php and equally the page which processes a delete would be deletefred.php. I like splitting the pages up this way, it feels less cluttered and more organised than throwing all the functionality in one fred.php.
4
2149
by: Terry | last post by:
I need some help refining an MS 2000 relational databse. I have created a simple relational database using two tables, 'Student Details', 'Exam Details' and two forms, 'Input/Edit Exam Details', 'Input/Edit Student Details'. 'Student Details' has a field called 'Log Book No' (no duplicates allowed) and this is the Primary Key. 'Exam Details' also has a field called 'Log Book No' (duplicates allowed) and has no Primary Key, (as each...
0
3120
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format. However, the DataGrid begins to get very cumbersome as the number of columns of data you present increases. Anything more than half a dozen columns or so and you probably induce horizontal scrolling - a real no-no for me. If you put such a...
0
1769
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page Private strConn As String =
1
3481
by: Kostis | last post by:
Hello there! I have created a windows application in VB.NET and I want to retrieve data from an access database. I create the OleDbConnection, an OleDbAdapter, a dataset and finally a Data Form using the Data Form Wizard. Everything works fine. The problem is that I want to use the masked edit control to manage the way some fields appear, and are being stored to the database. I insert the "Microsoft Masked Edit Control, version 6.0" (Path...
9
2734
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
9
7756
bhcob1
by: bhcob1 | last post by:
Hey guys, 'Update or CancelUpdate without AddNew or Edit' On my database i keep occasionly get this error when i try and edit a field, it is not everytime. It will be working fine and then this error appears. I will be editing records and then a random one will get the error. A bit of background on my form, this will seem a bit lengthy but here is my code. The form has a navigation list which the user can select a record to view. An...
8
1997
by: =?Utf-8?B?bWlrZWc=?= | last post by:
Hi, I am building a small Help Desk application for my company and need to be able to edit "open" help desk issues. I use a simple datagrid to display each issue (6 per page) , with an Edit button. There are a lot of fields across, and my Network Admins would like a way of editing/updating each issue seperately in a a vertical form. I need a way of clicking on the edit button ,bringing up a form with the record, editng the fields, and...
1
2168
by: ollielaroo | last post by:
Hi guys, Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site. My problem is I have Categories and various Products in each Category. I'm trying to build a page to EDIT/UPDATE each product.I want to be able to change the Category that a product belongs to, but all I get in the drop-down menu is the one specific Category. ...
1
3333
by: chromis | last post by:
Hi, I'm having trouble fully implementing the edit section of a contact admin system, so far I have written the following: - Bean (Contact.cfc) - Data Access object (ContactDAO.cfc) - Gateway (ContactGateway.cfc) - index.cfm - Deals with the business logic - display/form.cfm - Produces the form for both add and edit behaviour
0
9724
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10127
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.