creating php form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lolodede
    New Member
    • Apr 2009
    • 63

    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
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>Prac 3 Task 4</title>
    </head>
    <body>
    <?php
    $conn = odbc_connect("warehouse","IWSDStudent","assign2");
    $sql = "SELECT lastName ROM ocustomer ";
    $rs = odbc_exec($conn,$sql);
    ?>
     <form id="customerform" action="task10.php" method="get">
    <select name='class' size='1' >
    <option value='$cusID'>$lName</option>  
    </select>
    <?php
    while (odbc_fetch_array($sql))
    {
    $cusID = odbc_result($rs,"customerID");
    $lName = odbc_result($rs, "lastName");
    echo "";
    }
    odbc_close($conn);
    ?>
    <p><input type="submit"  value="Submit">
      <input type="reset" value="Reset"></p>
    </form>
    </body>
    </html>
    plz help
    Last edited by acoder; May 13 '09, 09:44 AM. Reason: Added [code] tags
  • prabirchoudhury
    New Member
    • May 2009
    • 162

    #2
    creating php form

    hey

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



    Code:
    <?php
    $conn = odbc_connect("warehouse","IWSDStudent","assign2");
    $sql = "SELECT lastName ROM ocustomer ";
    $rs = odbc_exec($conn,$sql);
    ?>
    <form id="customerform" action="task10.php" method="get">
    <select name='class' size='1' >
    
    
    <?php
    while (odbc_fetch_array($sql))
    {
    $cusID = odbc_result($rs,"customerID");
    $lName = odbc_result($rs, "lastName");
    ?>
    <option value='<? echo $cusID; ?>'><? echo $lName; ?></option> 
    <?
    }
    
    </select>
    odbc_close($conn);
    ?>
    <p><input type="submit" value="Submit">
    <input type="reset" value="Reset"></p>
    </form>
    good luck

    Comment

    • lolodede
      New Member
      • Apr 2009
      • 63

      #3
      reply to php form

      its working but i would like to retrieve information when i submit the form i cant i dont noe why
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
      <title>Prac 3 Task 4</title>
      </head>
      <body>
      <?php
      $conn = odbc_connect("warehouse","IWSDStudent","assign2");
      $sql = "SELECT lastName FROM customer ";
      $rs = odbc_exec($conn,$sql);
      ?>
       <form id="customerform" action="task10.php" method="get">
      <select name='class' size='1' >
      <?php
      while (odbc_fetch_array($rs))
      {
      $cusID = odbc_result($rs,"customerID");
      $lName = odbc_result($rs, "lastName");
      ?>
      <option value='<?php echo $cusID; ?>'><?php echo $lName; ?></option> 
      <?php
      }
      
      odbc_close($conn);
      ?>
       </select>
      <p><input type="submit" value="Submit">
      <input type="reset" value="Reset"></p>
      </form>
      </body>
      </html>
      then goes to this page to get information but it doesnt work 
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
      <title>Task 10 PHP</title>
      </head>
      
      <body>
      <?php 
      $cusID = $_GET["custID"];
      $conn = odbc_connect("warehouse","IWSDStudent","assign2");
      $sql= "SELECT orderNumber, orderDate,shipped FROM orders WHERE customerID= '$cusID'";
      $rs = odbc_exec($conn,$sql);
      ?>
      <table border="1" summary="product Details">
      <tr>
      <th>Order NO</th>
      <th>Order date </th>
      <th>Shipped</th>
      </tr> 
      <?php 
      if (odbc_num_rows($rs)>0) { // Got some data?
      while (odbc_fetch_row($rs))
      {
      $orderNo = odbc_result($rs,"orderNumber");
      $orderdate = odbc_result($rs, "orderDate");
      $shipped = odbc_result($rs,"shipped");
      echo "<tr><td>$orderNo</td>";
      echo "<td> $orderdate</td>";
      echo "<td> $shipped</td></tr>";
      
      }
              
            }
           
            else {
          
          // Display an error message if no data was retrieved or some other error condition was encountered.
      
          print "<p>There's no values for the customer id please try again: $cusID.</p>";
          print "<p><a href=\"task10.htm\">Return to try another number.</a></p>";
          
        }
        odbc_close($conn);
      ?>
        </body>
      </html>
      thanks alot for help i appreciate it
      Last edited by acoder; May 13 '09, 09:46 AM. Reason: Added [code] tags

      Comment

      • prabirchoudhury
        New Member
        • May 2009
        • 162

        #4
        thats great.. you are welcome ...

        Comment

        • lolodede
          New Member
          • Apr 2009
          • 63

          #5
          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

          Comment

          • prabirchoudhury
            New Member
            • May 2009
            • 162

            #6
            page one customer.php
            we are using $_GET method in the <form > to send those variables to the customer_detail s.php page using



            Code:
            <?xml version="1.0" encoding="UTF-8"?> 
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
            <head> 
            <title>Prac 3 Task 4</title> 
            </head> 
            <body> 
            <?php 
            $conn = odbc_connect("warehouse","IWSDStudent","assign2"); 
            $sql = "SELECT lastName FROM customer "; 
            $rs = odbc_exec($conn,$sql); 
            ?> 
             <form id="customerform" action="customer_details.php" method="GET"> 
            <select name='class' size='1' > 
            <?php 
            while (odbc_fetch_array($rs)) 
            { 
            $cusID = odbc_result($rs,"customerID"); 
            $lName = odbc_result($rs, "lastName"); 
            ?> 
            <option value='<?php echo $cusID; ?>'><?php echo $lName; ?></option>  
            <?php 
            } 
              
            odbc_close($conn); 
            ?> 
             </select> 
            <p><input type="submit" value="Submit"> 
            <input type="reset" value="Reset"></p> 
            </form> 
            </body> 
            </html>

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


            Code:
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
            <head> 
            <title>Task 10 PHP</title> 
            </head> 
              
            <body> 
            <?php  
            $cusID = $_GET["custID"]; 
            $conn = odbc_connect("warehouse","IWSDStudent","assign2"); 
            $sql= "SELECT orderNumber, orderDate,shipped FROM orders WHERE customerID= '$cusID'"; 
            $rs = odbc_exec($conn,$sql); 
            ?> 
            <table border="1" summary="product Details"> 
            <tr> 
            <th>Order NO</th> 
            <th>Order date </th> 
            <th>Shipped</th> 
            </tr>  
            <?php  
            if (odbc_num_rows($rs)>0) { // Got some data? 
            while (odbc_fetch_row($rs)) 
            { 
            $orderNo = odbc_result($rs,"orderNumber"); 
            $orderdate = odbc_result($rs, "orderDate"); 
            $shipped = odbc_result($rs,"shipped"); 
            echo "<tr><td>$orderNo</td>"; 
            echo "<td> $orderdate</td>"; 
            echo "<td> $shipped</td></tr>"; 
              
            } 
              
                  } 
              
                  else { 
              
                // Display an error message if no data was retrieved or some other error condition was encountered. 
              
                print "<p>There's no values for the customer id please try again: $cusID.</p>"; 
                print "<p><a href=\"task10.htm\">Return to try another number.</a></p>"; 
              
              } 
              odbc_close($conn); 
            ?> 
              </body> 
            </html>
            It should wrk fine, if doesnt wrk give me a buzz ..

            Comment

            • lolodede
              New Member
              • Apr 2009
              • 63

              #7
              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

              Comment

              • lolodede
                New Member
                • Apr 2009
                • 63

                #8
                link three pages together

                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

                Comment

                • prabirchoudhury
                  New Member
                  • May 2009
                  • 162

                  #9
                  creating php form

                  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..

                  Comment

                  • lolodede
                    New Member
                    • Apr 2009
                    • 63

                    #10
                    im new to php i dont know how to do hidden fields or query string
                    thanks again

                    Comment

                    • Ciary
                      Recognized Expert New Member
                      • Apr 2009
                      • 247

                      #11
                      Originally posted by lolodede
                      im new to php i dont know how to do hidden fields or query string
                      thanks again
                      hidden fields are easy just place the next code somewhere in your form
                      Code:
                      <input type="hidden" value="<?php echo $custID; ?>"/>
                      placing custID in a session isn't hard either:
                      Code:
                      $_SESSION['custID'] = $custID;
                      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:
                      Code:
                      is(!isset($_SESSION))
                      session_start()
                      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.
                      Code:
                      <a href="my/path/to/page.php?cusID=<?php echo $_GET['custID']; ?>">my link</a>
                      ofter that, you can use $_GET['custID'] on every page

                      Comment

                      • lolodede
                        New Member
                        • Apr 2009
                        • 63

                        #12
                        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

                        Comment

                        • Ciary
                          Recognized Expert New Member
                          • Apr 2009
                          • 247

                          #13
                          can you post your code (don't forget to use code-tags) then ill see what i can find

                          Comment

                          • lolodede
                            New Member
                            • Apr 2009
                            • 63

                            #14
                            my codes

                            first page
                            Code:
                            <?xml version="1.0" encoding="UTF-8"?>
                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
                            
                            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                            <head>
                            <title>Prac3 Task 10</title>
                            </head>
                            <body>
                             <h1>Task 10</h1>
                             <form id="customerform" action="task10.php" method="get">
                              <p>please fill in the following form</p>
                            <p>Customer ID:  <input type="text" name="custID"/><br/>
                            <p><input type="submit"  value="Submit">
                              <input type="reset" value="Reset"></p>
                             </form>
                            </body>
                            </html>
                            second page
                            Code:
                            <?xml version="1.0" encoding="UTF-8"?>
                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                            <head>
                            <title>Task 10 PHP</title>
                            </head>
                            
                            <body>
                            <?php
                            session_start();
                             $cusID = $_GET["custID"];
                            $_SESSION["who"] = $cusID;
                            ?>
                            <?php 
                            $conn = odbc_connect("warehouse","IWSDStudent","assign2");
                            $sql= "SELECT orderNumber, orderDate,shipped FROM orders WHERE customerID= '$cusID' ORDER BY orderDate ASC";
                            $rs = odbc_exec($conn,$sql);
                            ?>
                            <table border="1" summary="product Details">
                            <tr>
                            <th>Order NO</th>
                            <th>Order date </th>
                            <th>Shipped</th>
                            </tr> 
                            <?php 
                            if (odbc_num_rows($rs)>0) { // Got some data?
                            while (odbc_fetch_row($rs))
                            {
                            $orderNo = odbc_result($rs,"orderNumber");
                            $orderdate = odbc_result($rs, "orderDate");
                            $shipped = odbc_result($rs,"shipped");
                            echo "<tr><td>$orderNo</td>";
                            echo "<td> $orderdate</td>";
                            echo "<td> $shipped</td></tr>";
                            
                            }
                                    
                                  }
                                 
                                  else {
                                
                                // Display an error message if no data was retrieved or some other error condition was encountered.
                            
                                print "<p>There's no values for the customer id please try again: $cusID.</p>";
                                print "<p><a href=\"task10.htm\">Return to try another number.</a></p>";
                                
                              }
                              odbc_close($conn);
                            ?>
                              </body>
                            </html>
                            third page
                            Code:
                            <?xml version="1.0" encoding="UTF-8"?>
                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                            <head>
                            <title>Prac 3 Task 4</title>
                            </head>
                            <body>
                            <?php
                            session_start();
                            $cusID = $_SESSION["who"];
                            ?>
                            <?php
                            $conn = odbc_connect("warehouse","IWSDStudent","assign2");
                             $sql = "SELECT lastName  FROM customer  ";
                              $rs = odbc_exec($conn,$sql);
                            ?>
                             <form id="customerform" action="task10.php" method="get">
                            <input type="hidden" value="<?php echo $custID; ?>"/>
                            <select name='class' size='1'  >
                            <?php
                            while (odbc_fetch_array($rs))
                            {
                            $cusID = odbc_result($rs,"customerID");
                            $lName = odbc_result($rs, "lastName");
                            ?>
                            <option  value="<?php echo $cusID?>"> <?php echo $lName; ?></option> 
                            <?php
                            }
                             odbc_close($conn);
                            ?>
                            </select>
                            <p><input  type="submit" value="Submit">
                            <input type="reset" value="Reset"></p>
                            </form>
                            </body>
                            </html>
                            the third page is the problem

                            Comment

                            • Ciary
                              Recognized Expert New Member
                              • Apr 2009
                              • 247

                              #15
                              Code:
                              <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 :)

                              Comment

                              Working...