473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

creating php form

i would like to create form with drop down list that retrieve data from dtadbase
once and other page containg radio bottons but use information that saved in database
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <title>Prac 3 Task 4</title>
  7. </head>
  8. <body>
  9. <?php
  10. $conn = odbc_connect("warehouse","IWSDStudent","assign2");
  11. $sql = "SELECT lastName ROM ocustomer ";
  12. $rs = odbc_exec($conn,$sql);
  13. ?>
  14.  <form id="customerform" action="task10.php" method="get">
  15. <select name='class' size='1' >
  16. <option value='$cusID'>$lName</option>  
  17. </select>
  18. <?php
  19. while (odbc_fetch_array($sql))
  20. {
  21. $cusID = odbc_result($rs,"customerID");
  22. $lName = odbc_result($rs, "lastName");
  23. echo "";
  24. }
  25. odbc_close($conn);
  26. ?>
  27. <p><input type="submit"  value="Submit">
  28.   <input type="reset" value="Reset"></p>
  29. </form>
  30. </body>
  31. </html>
plz help
May 13 '09 #1
25 2239
prabirchoudhury
162 100+
hey

You have to put "<option > </option>" inside the while loop .. hav echang ethe code bellow



Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $conn = odbc_connect("warehouse","IWSDStudent","assign2");
  3. $sql = "SELECT lastName ROM ocustomer ";
  4. $rs = odbc_exec($conn,$sql);
  5. ?>
  6. <form id="customerform" action="task10.php" method="get">
  7. <select name='class' size='1' >
  8.  
  9.  
  10. <?php
  11. while (odbc_fetch_array($sql))
  12. {
  13. $cusID = odbc_result($rs,"customerID");
  14. $lName = odbc_result($rs, "lastName");
  15. ?>
  16. <option value='<? echo $cusID; ?>'><? echo $lName; ?></option> 
  17. <?
  18. }
  19.  
  20. </select>
  21. odbc_close($conn);
  22. ?>
  23. <p><input type="submit" value="Submit">
  24. <input type="reset" value="Reset"></p>
  25. </form>
good luck
May 13 '09 #2
its working but i would like to retrieve information when i submit the form i cant i dont noe why
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <title>Prac 3 Task 4</title>
  7. </head>
  8. <body>
  9. <?php
  10. $conn = odbc_connect("warehouse","IWSDStudent","assign2");
  11. $sql = "SELECT lastName FROM customer ";
  12. $rs = odbc_exec($conn,$sql);
  13. ?>
  14.  <form id="customerform" action="task10.php" method="get">
  15. <select name='class' size='1' >
  16. <?php
  17. while (odbc_fetch_array($rs))
  18. {
  19. $cusID = odbc_result($rs,"customerID");
  20. $lName = odbc_result($rs, "lastName");
  21. ?>
  22. <option value='<?php echo $cusID; ?>'><?php echo $lName; ?></option> 
  23. <?php
  24. }
  25.  
  26. odbc_close($conn);
  27. ?>
  28.  </select>
  29. <p><input type="submit" value="Submit">
  30. <input type="reset" value="Reset"></p>
  31. </form>
  32. </body>
  33. </html>
  34. then goes to this page to get information but it doesnt work 
  35. <?xml version="1.0" encoding="UTF-8"?>
  36. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  37. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  38. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  39. <head>
  40. <title>Task 10 PHP</title>
  41. </head>
  42.  
  43. <body>
  44. <?php 
  45. $cusID = $_GET["custID"];
  46. $conn = odbc_connect("warehouse","IWSDStudent","assign2");
  47. $sql= "SELECT orderNumber, orderDate,shipped FROM orders WHERE customerID= '$cusID'";
  48. $rs = odbc_exec($conn,$sql);
  49. ?>
  50. <table border="1" summary="product Details">
  51. <tr>
  52. <th>Order NO</th>
  53. <th>Order date </th>
  54. <th>Shipped</th>
  55. </tr> 
  56. <?php 
  57. if (odbc_num_rows($rs)>0) { // Got some data?
  58. while (odbc_fetch_row($rs))
  59. {
  60. $orderNo = odbc_result($rs,"orderNumber");
  61. $orderdate = odbc_result($rs, "orderDate");
  62. $shipped = odbc_result($rs,"shipped");
  63. echo "<tr><td>$orderNo</td>";
  64. echo "<td> $orderdate</td>";
  65. echo "<td> $shipped</td></tr>";
  66.  
  67. }
  68.  
  69.       }
  70.  
  71.       else {
  72.  
  73.     // Display an error message if no data was retrieved or some other error condition was encountered.
  74.  
  75.     print "<p>There's no values for the customer id please try again: $cusID.</p>";
  76.     print "<p><a href=\"task10.htm\">Return to try another number.</a></p>";
  77.  
  78.   }
  79.   odbc_close($conn);
  80. ?>
  81.   </body>
  82. </html>
thanks alot for help i appreciate it
May 13 '09 #3
prabirchoudhury
162 100+
thats great.. you are welcome ...
May 13 '09 #4
what about the revealing information from first page to next page and i dont know how to link them to show information that customer order
thanks
May 13 '09 #5
prabirchoudhury
162 100+
page one customer.php
we are using $_GET method in the <form > to send those variables to the customer_details.php page using



Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
  5. <head> 
  6. <title>Prac 3 Task 4</title> 
  7. </head> 
  8. <body> 
  9. <?php 
  10. $conn = odbc_connect("warehouse","IWSDStudent","assign2"); 
  11. $sql = "SELECT lastName FROM customer "; 
  12. $rs = odbc_exec($conn,$sql); 
  13. ?> 
  14.  <form id="customerform" action="customer_details.php" method="GET"> 
  15. <select name='class' size='1' > 
  16. <?php 
  17. while (odbc_fetch_array($rs)) 
  18. $cusID = odbc_result($rs,"customerID"); 
  19. $lName = odbc_result($rs, "lastName"); 
  20. ?> 
  21. <option value='<?php echo $cusID; ?>'><?php echo $lName; ?></option>  
  22. <?php 
  23.  
  24. odbc_close($conn); 
  25. ?> 
  26.  </select> 
  27. <p><input type="submit" value="Submit"> 
  28. <input type="reset" value="Reset"></p> 
  29. </form> 
  30. </body> 
  31. </html> 

page tow customer_details.php . you could chabge the pagename what evr you want.
we get back posted variables frm here $variable = $_GET["namefild_ofthe_tag"]


Expand|Select|Wrap|Line Numbers
  1.  
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
  3. <head> 
  4. <title>Task 10 PHP</title> 
  5. </head> 
  6.  
  7. <body> 
  8. <?php  
  9. $cusID = $_GET["custID"]; 
  10. $conn = odbc_connect("warehouse","IWSDStudent","assign2"); 
  11. $sql= "SELECT orderNumber, orderDate,shipped FROM orders WHERE customerID= '$cusID'"; 
  12. $rs = odbc_exec($conn,$sql); 
  13. ?> 
  14. <table border="1" summary="product Details"> 
  15. <tr> 
  16. <th>Order NO</th> 
  17. <th>Order date </th> 
  18. <th>Shipped</th> 
  19. </tr>  
  20. <?php  
  21. if (odbc_num_rows($rs)>0) { // Got some data? 
  22. while (odbc_fetch_row($rs)) 
  23. $orderNo = odbc_result($rs,"orderNumber"); 
  24. $orderdate = odbc_result($rs, "orderDate"); 
  25. $shipped = odbc_result($rs,"shipped"); 
  26. echo "<tr><td>$orderNo</td>"; 
  27. echo "<td> $orderdate</td>"; 
  28. echo "<td> $shipped</td></tr>"; 
  29.  
  30.  
  31.       } 
  32.  
  33.       else { 
  34.  
  35.     // Display an error message if no data was retrieved or some other error condition was encountered. 
  36.  
  37.     print "<p>There's no values for the customer id please try again: $cusID.</p>"; 
  38.     print "<p><a href=\"task10.htm\">Return to try another number.</a></p>"; 
  39.  
  40.   } 
  41.   odbc_close($conn); 
  42. ?> 
  43.   </body> 
  44. </html> 
  45.  
It should wrk fine, if doesnt wrk give me a buzz ..
May 14 '09 #6
it doesnt work because the error says custID undifiend and i cant change custID because its related to html form to recieve information through ID
thanks
May 14 '09 #7
thats what i need to do when customer go to page id then its goes to order detail or customer view page with thier name then again its goes to order detail the first two pages work but the other two dont because (custID in order details is undefined into customer page names) please help
the above codes that what i have
May 14 '09 #8
prabirchoudhury
162 100+
if you select one custID and wanna go to different pages to for this customer information then you have to define every time custID to different pages.

you could define custID in different way

1. assign custID as a hidden field when goes to other page

2. pass custID as query string and get custID frm the next page

$custID= $_get['custID'];

3. could assign as a $_session to define custID from different page

and when customer come back to select another custID then old session die and reassign new custID


but i would suggest to assign custID in query string or hidden field


until select a new custID old first time selected custID would be passed in different pages and would be defined first and then get data of that custID.

that how should work.. if you need more help just buzz..
May 14 '09 #9
im new to php i dont know how to do hidden fields or query string
thanks again
May 14 '09 #10
Ciary
247 Expert 100+
@lolodede
hidden fields are easy just place the next code somewhere in your form
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" value="<?php echo $custID; ?>"/>
  2.  
placing custID in a session isn't hard either:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['custID'] = $custID;
  2.  
after that, you can simply get it on every page with $_SESSION['custID'] but you'll have to start a session. therefor add this code on top of every page:
Expand|Select|Wrap|Line Numbers
  1. is(!isset($_SESSION))
  2. session_start()
  3.  
the idea of query string will cost you a lot of work to implement but it's certainly one of the best ways. you'll have to change every href to this.
Expand|Select|Wrap|Line Numbers
  1. <a href="my/path/to/page.php?cusID=<?php echo $_GET['custID']; ?>">my link</a>
  2.  
ofter that, you can use $_GET['custID'] on every page
May 14 '09 #11
sorry again but its not working im realy getting confused wat im missing its same error again and again custID undefined ive tried different things but not working id not know what to do
thanks
May 14 '09 #12
Ciary
247 Expert 100+
can you post your code (don't forget to use code-tags) then ill see what i can find
May 14 '09 #13
first page
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6. <head>
  7. <title>Prac3 Task 10</title>
  8. </head>
  9. <body>
  10.  <h1>Task 10</h1>
  11.  <form id="customerform" action="task10.php" method="get">
  12.   <p>please fill in the following form</p>
  13. <p>Customer ID:  <input type="text" name="custID"/><br/>
  14. <p><input type="submit"  value="Submit">
  15.   <input type="reset" value="Reset"></p>
  16.  </form>
  17. </body>
  18. </html>
  19.  
second page
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <title>Task 10 PHP</title>
  7. </head>
  8.  
  9. <body>
  10. <?php
  11. session_start();
  12.  $cusID = $_GET["custID"];
  13. $_SESSION["who"] = $cusID;
  14. ?>
  15. <?php 
  16. $conn = odbc_connect("warehouse","IWSDStudent","assign2");
  17. $sql= "SELECT orderNumber, orderDate,shipped FROM orders WHERE customerID= '$cusID' ORDER BY orderDate ASC";
  18. $rs = odbc_exec($conn,$sql);
  19. ?>
  20. <table border="1" summary="product Details">
  21. <tr>
  22. <th>Order NO</th>
  23. <th>Order date </th>
  24. <th>Shipped</th>
  25. </tr> 
  26. <?php 
  27. if (odbc_num_rows($rs)>0) { // Got some data?
  28. while (odbc_fetch_row($rs))
  29. {
  30. $orderNo = odbc_result($rs,"orderNumber");
  31. $orderdate = odbc_result($rs, "orderDate");
  32. $shipped = odbc_result($rs,"shipped");
  33. echo "<tr><td>$orderNo</td>";
  34. echo "<td> $orderdate</td>";
  35. echo "<td> $shipped</td></tr>";
  36.  
  37. }
  38.  
  39.       }
  40.  
  41.       else {
  42.  
  43.     // Display an error message if no data was retrieved or some other error condition was encountered.
  44.  
  45.     print "<p>There's no values for the customer id please try again: $cusID.</p>";
  46.     print "<p><a href=\"task10.htm\">Return to try another number.</a></p>";
  47.  
  48.   }
  49.   odbc_close($conn);
  50. ?>
  51.   </body>
  52. </html>
  53.  
third page
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <title>Prac 3 Task 4</title>
  7. </head>
  8. <body>
  9. <?php
  10. session_start();
  11. $cusID = $_SESSION["who"];
  12. ?>
  13. <?php
  14. $conn = odbc_connect("warehouse","IWSDStudent","assign2");
  15.  $sql = "SELECT lastName  FROM customer  ";
  16.   $rs = odbc_exec($conn,$sql);
  17. ?>
  18.  <form id="customerform" action="task10.php" method="get">
  19. <input type="hidden" value="<?php echo $custID; ?>"/>
  20. <select name='class' size='1'  >
  21. <?php
  22. while (odbc_fetch_array($rs))
  23. {
  24. $cusID = odbc_result($rs,"customerID");
  25. $lName = odbc_result($rs, "lastName");
  26. ?>
  27. <option  value="<?php echo $cusID?>"> <?php echo $lName; ?></option> 
  28. <?php
  29. }
  30.  odbc_close($conn);
  31. ?>
  32. </select>
  33. <p><input  type="submit" value="Submit">
  34. <input type="reset" value="Reset"></p>
  35. </form>
  36. </body>
  37. </html>
the third page is the problem
May 14 '09 #14
Ciary
247 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. <option  value="<?php echo $cusID?>"> <?php echo $lName; ?></option>
on this line? i'm not sure if it causes the problem but you forgot a ; after $cusID

EDIT: it's great to see you use codetags :)
May 14 '09 #15
its undefined custID when i submit the third page
May 14 '09 #16
Ciary
247 Expert 100+
ah ok then you have to edit this line i think:
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" value="<?php echo $custID; ?>"/>
to this
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" id="cusID" name="cusID" value="<?php echo $cusID; ?>"/>
after this you can get its value using $_GET['cusID']
May 14 '09 #17
sorry but im really confused more its should be working but not it doest i try wat did u said and it doesnt work same error again and again
May 14 '09 #18
Ciary
247 Expert 100+
on what line do you get the error and in which file (second or third)?
May 14 '09 #19
the third page when i submit it and if i put ur line into my code there are more errors like undefined cusID before submit and after submit it to task10.php on that page appear undefined error of custID line 12 which is line get
May 14 '09 #20
Ciary
247 Expert 100+
ok i think i know where the problem is. try changing every cusID you can find to custID. do this in all three files
May 14 '09 #21
i did this and receive this message Undefined index: custID in task10.php on line 12
May 14 '09 #22
Ciary
247 Expert 100+
can you post the code of task10.php? since you changed a few things i dont know what line 12 is anymore :)

EDIT: just to verify, try putting the next code as first line:
Expand|Select|Wrap|Line Numbers
  1. <?php if($_SERVER["REQUEST_METHOD"] == "GET"){?>
and this code at the end of the file:
Expand|Select|Wrap|Line Numbers
  1. <?php }else{echo "ERROR!!";}?>
what do you see now?
May 14 '09 #23
How accordingly sir....how.....i have clear that i have three database tables like tbl_a, tbl_b, tbl_c & which have corresponding fields a_id,a_name,b_id,b_name,c_id,c_name. In php page there 3 text box for different table input inside on HTML form. I need to input these three tex box value to different table on database tbl_a,tbl_b,tbl_c. so plz give me idea.don't give me confusen answer..if u don't understand my problem then tell me clearly in which part r u not able to understand. plz
Ur help will be appreciated...
May 17 '09 #24
Ciary
247 Expert 100+
to luckysanj: you've already asked this on a different thread. the answer is given there. all you need to do is post your form and write one SQL query for each table in which you want to insert/update a record.

also this thread is ment to answer lolodede's question. so only questions or answers linked to his/her question may be posted here.

please read the posting guidelines
May 17 '09 #25
Ok sorry for my mistake to post on other thread.
May 17 '09 #26

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

Similar topics

1
by: Don Stefani | last post by:
Hello, I have a form that I want to submit "onchange", OK I've got that working, but when the form submits, I want to pass along a value to a CGI script, as if that value was in a hidden form...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
2
by: Ben | last post by:
My current project requires me to create part of a form that is created on the fly. The project consists a list of entries to an event. The name and address and such is easy. The design is detup so...
2
by: Iain Miller | last post by:
Now this shouldn't be hard but I've been struggling on the best way as to how to do this one for a day or 3 so I thought I'd ask the assembled company..... I'm writing an application that tracks...
0
by: James Fortune | last post by:
Here is an example of Access creating a single page PDF file. The text in the textbox is scaled to fit horizontally into a grey box 100 pixels wide that is fontsize pixels high. Clicking the...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
3
by: Marius Rus | last post by:
I have an application write in c# and i want to offer to the user to create himself shortcuts with icons for the main menu items. I will very much appreciate if will receive an helping hand. Thank...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
3
by: solargovind | last post by:
Hi, I am New to this forum. I need steps that i do in creating subform. In main form, i have one table fields like vendor,account,due amount,balance amount and Requisition_id which is...
1
by: OxfordConsult | last post by:
I have a form and it is to creat a 'link' between a project and a company. Creating a record form this table will simply create a record in a databse with the company ID and project ID. Project ID is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
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,...
0
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...

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.