473,624 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I populate a form from database and update database on one page

5 New Member
Without going into great detail (which I can do if it turns out more info is needed), I would like to:

All on one page, using ajax:
1. In a text field, have the user enter a plant name to insert into a database
2. Have a form pop up with attributes for the plant (name, scientific name, related species)
3. Have the user fill this field out and submit it to a mysql database table.

So far I have part 1 and 2 working. However, I cannot figure out how to continue to part 3 without submitting the data and loading to the next page for confirmation of insertion.

Please look and see what I've accomplished so far at this link

I can provide further information and source if it is needed. Thanks

Esscher
Feb 22 '08 #1
2 1548
esscher
5 New Member
It might be helpful for you to run the code yourself, so i'll include my sources

demo_add_plant. php
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script src="showplantprofileform.js"></script>
  5.  
  6.  
  7. <script language="javascript">
  8.  var url = "add_plant_profile_record.php?id="; 
  9.  
  10.        function handleHttpResponse() {   
  11.         if (http.readyState == 4) {
  12.               if(http.status==200) {
  13.                   var results=http.responseText;
  14.               document.getElementById('PlantInfoDiv').innerHTML = results;
  15.               }
  16.               }
  17.         }
  18.  
  19.         function showPlantProfileForm() {     
  20.             var sId = document.getElementById("Plant2Check").value;
  21.             http.open("GET", url + escape(sId), true);
  22.             http.onreadystatechange = handleHttpResponse;
  23.             http.send(null);
  24.         }
  25. function getHTTPObject() {
  26.   var xmlhttp;
  27.  
  28.   if(window.XMLHttpRequest){
  29.     xmlhttp = new XMLHttpRequest();
  30.  
  31.   }
  32.   else if (window.ActiveXObject){
  33.     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  34.     if (!xmlhttp){
  35.         xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  36.     }
  37.  
  38. }
  39.   return xmlhttp;
  40.  
  41.  
  42. }
  43. var http = getHTTPObject();
  44. </script>
  45.  
  46. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  47. <title>Phytobase Home</title>
  48. </head>
  49. <body bgcolor="white">
  50.  
  51. <form>
  52. Add Plant Profile (type anything):<input id="Plant2Check" type="text" name="inputplant" value="">
  53. <p><input type="button" value="Click 4 Plant Profile Form" onClick="showPlantProfileForm()" />
  54.  
  55. </form>
  56. <div id="PlantInfoDiv"><b>Plant info will be listed here.</b></div>
  57.  
  58. </body>
  59. </html>
  60.  
add_plant_profi le_record.php
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3. include ("privatedbconfig.php");
  4. include ("dbconnection.php");
  5.  
  6.  
  7. echo "You've requested to add " .$_GET['id'] .".<br>";
  8.  
  9. $result=mysql_query("select * from plants where common_name='$inputplant'");
  10. $numrows=mysql_num_rows($result);
  11. if ($numrows > 0) 
  12.  {
  13.  echo "Plant is already in database.  Cannot Insert";
  14.  ?><a href="http://66.87.141.7/phytobase/p2/home.html">Click to Return Home</a><?php
  15.  }
  16. else
  17.  {
  18. ?>
  19. <html xmlns="http://www.w3.org/1999/xhtml">
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  22. </head>
  23.  
  24. <body>
  25. <form id="add_plant_profile_record" name="add_plant_profile_record">
  26.  
  27. <table border="1" cellpadding="3" cellspacing="0">
  28. <tr>
  29. <td align="center" bgcolor="#FFCC00"><strong>Property</strong></td>
  30. <td align="center" bgcolor="#FFCC00"><strong>What to Insert</strong></td>
  31. <?php
  32. ?>
  33.  
  34. </tr>
  35. <tr>
  36. <td bgcolor="#FFFFCC"><?php echo "Common Name";  ?></td>
  37. <td bgcolor="#FFFFCC"><input name="common_name" type="text" value="<?php echo $_GET['id'] ?>"</td>
  38. </tr>
  39. <tr>
  40. <td bgcolor="#FFFFCC"><?php echo "Additional Names";  ?></td>
  41. <td bgcolor="#ffffcc"><textarea  name="additional_names" value=""></textarea></td>
  42. </tr>
  43. <tr>
  44. <td bgcolor="#FFFFCC"><?php echo "Genus";  ?></td>
  45. <td bgcolor="#ffffcc"><input id="genus" name="genus" type="text" value="" /></td>
  46. </tr>
  47. <tr>
  48. <td bgcolor="#FFFFCC"><?php echo "Species";  ?></td>
  49. <td bgcolor="#ffffcc"><input name="species" type="text" value="" /></td>
  50. </tr>
  51. <tr>
  52. <td bgcolor="#FFFFCC"><?php echo "Part Used";  ?></td>
  53. <td bgcolor="#ffffcc"><input name="part_used" type="text" value=""/></td>
  54. </tr>
  55. <tr>
  56. <td bgcolor="#FFFFCC"><?php echo "Warnings";  ?></td>
  57. <td bgcolor="#ffffcc"><textarea id="main" name="warnings" value=""></textarea></td>
  58. </tr>
  59. <tr>
  60. <td bgcolor="#FFFFCC"><?php echo "Picture";  ?></td>
  61. <td bgcolor="#ffffcc"><textarea name="picture" value=""></textarea></td>
  62. </tr>
  63. <tr>
  64. <td bgcolor="#FFFFCC"><?php echo "Effects";  ?></td>
  65. <td bgcolor="#ffffcc"><textarea id="main" name="fx"></textarea></td>
  66. </tr>
  67. <tr>
  68. <td bgcolor="#FFFFCC"><?php echo "Law";  ?></td>
  69. <td bgcolor="#ffffcc"><input name="law" type="text" value=""/></td>
  70. </tr>
  71. <tr>
  72. <td bgcolor="#FFFFCC"><?php echo "Native Land";  ?></td>
  73. <td bgcolor="#ffffcc"><input name="native_land" type="text" value=""/></td>
  74. </tr>
  75. <tr>
  76. <td bgcolor="#FFFFCC"><?php echo "Social Group";  ?></td>
  77. <td bgcolor="#ffffcc"><input name="social_group" type="text" value=""/></td>
  78. </tr>
  79. <tr>
  80. <td bgcolor="#FFFFCC"><?php echo "Additional Notes";  ?></td>
  81. <td bgcolor="#ffffcc"><textarea name="notes" value=""></textarea></td>
  82. </tr>
  83. <tr>
  84. <td bgcolor="#FFFFCC"><?php echo "References";  ?></td>
  85. <td bgcolor="#ffffcc"><textarea name="ref"  value=""></textarea></td>
  86. </tr>
  87. </table>
  88. <input type="button" name="submit_plant_profile" onClick="submit_plant_profile_data()" value="Add Info to DB" />
  89. </form><p>
  90. <div id="putItHere">This should change when the data has been inserted</div>
  91. <br>
  92.  
  93. </body>
  94. </html>
  95.  
  96. </body>
  97. </html>
  98. <?php
  99. }
  100. ?>
  101.  
plants mysql table
Expand|Select|Wrap|Line Numbers
  1. --
  2. -- Table structure for table `plants`
  3. --
  4.  
  5. CREATE TABLE `plants` (
  6.   `id` smallint(6) NOT NULL auto_increment,
  7.   `common_name` varchar(255) NOT NULL default '',
  8.   `additional_names` varchar(2000) default NULL,
  9.   `genus` varchar(255) default NULL,
  10.   `species` varchar(255) default NULL,
  11.   `warnings` varchar(2000) default NULL,
  12.   `picture` varchar(255) default NULL,
  13.   `fx` varchar(2000) default NULL,
  14.   `law` varchar(1000) default NULL,
  15.   `native_land` varchar(255) default NULL,
  16.   `social_group` varchar(2000) default NULL,
  17.   `notes` varchar(10000) default NULL,
  18.   `ref` varchar(1000) default NULL,
  19.   PRIMARY KEY  (`id`,`common_name`)
  20. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;
  21.  
  22. --
  23. -- Dumping data for table `plants`
  24. --
  25.  
  26. INSERT INTO `plants` (`id`, `common_name`, `additional_names`, `genus`, `species`, `warnings`, `picture`, `fx`, `law`, `native_land`, `social_group`, `notes`, `ref`) VALUES
  27. (1, 'kava kava', 'none', 'piper', '', '', '', 'sedative', '', '', '', '', '')
  28.  
Thanks for checking this out and helping

esscher
Feb 23 '08 #2
acoder
16,027 Recognized Expert Moderator MVP
See an AJAX POST example. Post the values entered to a script which inserts the values into the MySQL database.
Feb 25 '08 #3

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

Similar topics

9
2363
by: cooldv | last post by:
i know how to replace the sign " when SUBMITTING a form in asp by this code: message = Replace(usermessage, "'", "''"). My problem is DISPLAYING data in an asp FORM, from an an access database, when the data already contains a " sign problem is like this: access database .... to update on the internet .... a *dataupdate.asp* page ..... On this page, the data gets displayed in a form where i
4
2710
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display .="<li>".$wohdate."</li>" ; $TemplateText = Replace($TemplateText,"@$wohdisplayndx@",$woh_display);
2
3830
by: Mal P | last post by:
Hi there, I'm a J2EE fellow who (as usual) has been thrown in the deep end and have to learn a fair chunk of the .NET platform (VS, ADO, WebForms, C# etc) in roughly two days. I'm doing ok so far, but am wondering on a better way to do something... Basically, I have a form which has a few fields the user fills in. When submitted, the data is stored as a row in an SQL database table. Then, I have another page which lists all the rows...
0
2421
by: Nithin | last post by:
My code as an txt attachment. I have 2 drop down list boxes that on selection populate text boxes from my database table. I am able to display the correct values in these text boxes. I have 2 questions: 1) I would like the user update these text fields that get populated with data from the database. For some reason I get the error when I change the textbox value.
3
2688
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other words, a webpage may have to refer to 1 or more DataTables to populate itself. Therefore, a...
1
6500
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp page. I am able to call values from file in my jsp page. But as dynamic values can be any in no...
3
2671
by: eholz1 | last post by:
Hello PHP programmers. I had a brilliant idea on one of my pages that selects some data from my mysql database. I first set the page up to display some info and an image, just one item, with a row of data, etc. then I thought it would be nice to do a select, and perhaps an update (the title of the image) on the same page.
3
1848
by: MIkeC | last post by:
Apologies if this has already been posted. I am coding in VB I am trying to find the best way to populate a form from a sql Database in .net 2005 I have a company table that has > 20 columns, I will be selecting a specific row. I have populated the form with textboxes that are named so that they reflect the column names of the company table. I want to select the row, populate the form by looping through the columns.
1
3312
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
8680
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...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8478
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
7164
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...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
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
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.