473,507 Members | 3,706 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 1544
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_profile_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
2358
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,...
4
2702
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...
2
3824
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...
0
2412
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...
3
2682
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...
1
6483
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...
3
2659
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...
3
1845
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...
1
3301
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...
0
7221
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
7109
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...
1
7029
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...
0
7481
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...
1
5039
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...
0
4702
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...
0
3190
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
411
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...

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.