PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    Fill Form with data

    Share
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Fill Form with data

    Post  mbrad on Mon Mar 16, 2009 2:21 pm

    Does anyone know how to fill a form with data from the database? I'm trying to use useredit.php as an example, but can't quite follow it all the way through.

    What is the logic I need to follow. Perhaps if I know that, I'll be able to figure out the rest myself.

    Right now I have a function in process.php that gets the data for the specific record I want, and puts it into an array. I just need to know how to get it into the form. I've looked at form.php a lot, but can't figure out how to apply it to this situation.

    Thanks,

    Brad
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Mon Mar 16, 2009 6:02 pm

    Its pretty simple really.

    Lets say your array is called $row. You should try something like this:
    Code:
    <input type="text" value="<?php echo $row['some_value'] ?>">

    Hope that helps!


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Tue Mar 17, 2009 5:59 pm

    Ah yes, that makes sense. I think I've lost site of it all, trying to figure this out.

    So if I have a Class called Form2 I could do Form2->field_name as long as I make Form2 an array?

    Right now when you click the button, it fires my function in process.php The function gets the data from MySQL, I just have to assign it to something so that I can pass it back to the form... hence the new class Form2. I've never made my own class before, which is a part of my stumbling...

    I'll see if I can apply your help to my page.

    Thanks so very much for your reply.

    Brad
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Tue Mar 17, 2009 6:37 pm

    So if I have a Class called Form2 I could do Form2->field_name as long as I make Form2 an array?
    yep, thats how to do it.

    Im curious though, why are you creating a new class for this? Do you need this array available to your whole site? If you are just fetching data from your database and you are using the mysql_fetch_array function this puts your data into an array automatically.

    for instance, consider the following:
    Code:
    $q = "SELECT * FROM ".TBL_USERS." WHERE `id` = 1 LIMIT 1";
    $result = mysql_query($q);
    $row = mysql_fetch_array($result);

    now this is your standard database query and fetch. this will put all the data from the first row (or i should say, the row where id equals 1) into an array called $row. you can call values out of the array by typing $row['email']. And again, to call one of these values inside a forms text field you would to something like
    Code:
    <input type="text" name="some_name" value="<?php echo $row['email'] ?>">

    Dont let me stop you from using classes, if you need them, go ahead and create a new class in the script. but if you are just displaying some data from your table the extra work of implementing the class might not be worth it.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Tue Mar 17, 2009 11:48 pm

    That's what I thought, but the php login system uses classes to get this done, so I was wondering if I had to.

    I have this code, but I don't understand how to pass the results to my next page that has the form I want to populate.

    Code:
    function procEditContact(){
          global $database, $session, $form;
          /* Account edit attempt */
          echo "<script>alert('Got Here');</script>";
         echo "<script>alert('".$_POST['rowIDCont']."');</script>";
         //This $retval is from useredit
         //$retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email'], $_POST['UsrAvitar'], $_POST['UsrAvitarPath']);
        $q = "SELECT `LastName`, `FirstName`, `Phone1`, `Phone2`, `Mobile1`, `Mobile2`, `emailadd`, `emailadd2`, `Country`, `Address`, `PostalZipCode`, `ProvState`, `City`, `Notes`, `tblContactID` FROM `tblcontact` WHERE `tblContactID`=".$_POST['rowIDCont'];
         $retval = $database->query($q);
         echo "<script>alert('Got Here2');</script>";
        
         $ContactArray = array();
        
         $ContactArray = mysql_fetch_array($retval);
         echo "<script>alert('".$ContactArray['LastName']."');</script>";
        
        
         echo "<script>alert('Got Here3');</script>";
        
          //*********************Now how do I get it in the form on my page edit_contact.php********************
          //header("Location: ".$session->referrer);
      }

    The above code gets fired when this button is clicked. This code is a row in a table. The table has contact info in it. If the user wants to edit the contact info, they click the Edit button (code below).

    Code:
    echo "<form action=\"process.php\" method=\"POST\"><input type=\"hidden\" name=\"rowIDCont\" value=\"" . $row['tblContactID']. "\" /><input type=\"hidden\" name=\"subEditContact\" value=\"1\" /><input type=\"submit\" value=\"Edit\" /><span id=\"result\"" . $value . "\" style=\"display:none; background:green;\"></span><span>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#top\" class=\"TopLink\">Top</a></span></form>";

    So $value == the recordID from the table in MySQL, that way I'm looking for a unique value. This value is being passed to the function procEditContact() above. From procEditContact I want to go to edit_contact.php which has this form:

    Code:
    <form action="process.php" method="POST">
             <table border="0" cellspacing="0" cellpadding="3" id="NewMessage">
                <tr>
                       <td>Last Name:</td><td><input id="lastname" name="lastname" value="<?php echo $form->value("LastName"); ?>" /></td><td><?php echo $form->error("lastname"); ?></td>
                        <td>First Name:</td><td><input id="firstname" name="firstname" value="<?php echo $form->value("FirstName"); ?>" /></td><td><?php echo $form->error("firstname"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>
                       <td>Phone 1:</td><td><input id="phone1" name="phone1" value="<?php echo $form->value("Phone1"); ?>" /></td><td><?php echo $form->error("phone1"); ?></td>
                   <td>Phone 2:</td><td><input id="phone2" name="phone2" value="<?php echo $form->value("Phone2"); ?>" /></td><td><?php echo $form->error("phone2"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>Mobile 1:</td><td><input id="mobile1" name="mobile1" value="<?php echo $form->value("Mobile1"); ?>" /></td><td><?php echo $form->error("mobile1"); ?></td>
                        <td>Mobile 2:</td><td><input id="mobile2" name="mobile2" value="<?php echo $form->value("Mobile2"); ?>" /></td><td><?php echo $form->error("mobile2"); ?></td>
                       
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>E-mail 1:</td><td><input id="emailadd" name="emailadd" value="<?php echo $form->value("emailadd"); ?>" /></td><td><?php echo $form->error("emailadd"); ?></td>
                        <td>E-mail 2:</td><td><input id="emailadd2" name="emailadd2" value="<?php echo $form->value("emailadd2"); ?>" /></td><td><?php echo $form->error("emailadd2"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>Country:</td><td><input id="country" name="country" value="<?php echo $form->value("Country"); ?>" /></td><td><?php echo $form->error("country"); ?></td>
                        <td>Prov/State:</td><td><input id="provstate" name="provstate" value="<?php echo $form->value("ProvState"); ?>" /></td><td><?php echo $form->error("provstate"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>City:</td><td><input id="city" name="city" value="<?php echo $form->value("City"); ?>" /></td><td><?php echo $form->error("city"); ?></td>
                        <td>Address:</td><td><input id="address" name="address" value="<?php echo $form->value("Address"); ?>" /></td><td><?php echo $form->error("address"); ?></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                       <td>Postal/Zip:</td><td><input id="postalzip" name="postalzip" value="<?php echo $form->value("PostalZipCode"); ?>" /></td><td><?php echo $form->error("postalzip"); ?></td>
                        <td>Notes:</td><td><input id="notes" name="notes" value="<?php echo $form->value("Notes"); ?>" /></td><td><?php echo $form->error("notes"); ?></td>
                        <td>&nbsp;</td><td align="right"><input type="hidden" id="subNewContact" name="subNewContact" value="1" /><input type="submit" value="Save" /></td>
                    </tr>
                </table>
          </form>

    This code is based off of useredit.php which comes in the .zip file of the php Login System. In there it has values for <input /> like
    Code:
     value="<?php echo $form->value("curpass"); ?>"
    So I thought I'd have to do the same on my form.

    Thanks again for your help. This is slowly starting to come together in my head... Thanks for your patience.

    Brad
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Wed Mar 18, 2009 12:16 pm

    ok, so just to make sure we are on the same page... you are basically using modified versions of userinfo and useredit? if you are successfully retrieving the database info and displaying it in userinfo, can you just do the same on useredit to populate the form?

    now keep in mind editing the form will be a different story. dont forget to take a look at the editAccount function in session.php


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Wed Mar 18, 2009 12:41 pm

    Well I'm not using them exactly. I made my own form, but am using the value="<ph... part. I thought it would work just like that, but I don't know how to get my array to be used by the Form class, as the value of the <input /> is equal to $form->value("LastName"); for example. How do I get the array $ContactArray from the function procEditContact() into into the Form class? That's really where I'm stuck... I think. scratch

    I can see that for useredit.php it is based on the $session class and I think that's how the $form class works too, based on the session, as it seems to only return user info. Am I wrong on that, or am I not reading forms.php correctly?

    I didn't make any changes to the useredit.php page.

    Thanks again,

    Brad
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Wed Mar 18, 2009 1:26 pm

    alright, well i think we need to take a closer look at your code. the form you created, what page is it going on? userinfo uses the $database->getUserInfo function to query the database and return the info in the $req_user_info array. you can use this variable to call values like $req_user_info['LastName'] like we talked about earlier.

    If i am correctly understanding what you are trying to accomplish this might be your best option...


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Wed Mar 18, 2009 1:34 pm

    Would it help for me to post the code of my edit_contact.php, process.php and phonebook.php? There is a lot of code there.. not sure if it will fit. Can we attach files here?

    Brad
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Wed Mar 18, 2009 1:39 pm

    yea post everything you got, thats the best way to troubleshoot problems.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Mon Mar 30, 2009 2:41 pm

    Ok, with some great help from Linchpin311, I now have a solution.

    The solution is as follows:

    The user is on phonebook.php and clicks the edit button to edit the contact info.
    Code:
       echo "<form action=\"edit_contact.php\" method=\"POST\"><input type=\"hidden\" name=\"rowIDCont\" value=\"" . $row['tblContactID']. "\" /><input type=\"submit\" value=\"Edit\" /><span>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#top\" class=\"TopLink\">Top</a></span></form>";

    This then brings teh user to the edit_contact.php page that has a form on it ready to receive the info from the database. (form seen below)
    Code:
    <form action="process.php" method="POST">
             <table border="0" cellspacing="0" cellpadding="3" id="NewMessage">
                <tr>
                       <td>Last Name:</td><td><input id="lastname" name="lastname" value="<?php echo $session->ContactInfo("LastName"); ?>" /></td><td><?php echo $form->error("LastName"); ?></td>
                        <td>First Name:</td><td><input id="firstname" name="firstname" value="<?php echo $session->ContactInfo("FirstName"); ?>" /></td><td><?php echo $form->error("firstname"); ?></td>
                        <td>&nbsp;</td>
               </tr>
                    <tr>
                       <td>Phone 1:</td><td><input id="phone1" name="phone1" value="<?php echo $session->ContactInfo("Phone1"); ?>" /></td><td><?php echo $form->error("Phone1"); ?></td>
                   <td>Phone 2:</td><td><input id="phone2" name="phone2" value="<?php echo $session->ContactInfo("Phone2"); ?>" /></td><td><?php echo $form->error("Phone2"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>Mobile 1:</td><td><input id="mobile1" name="mobile1" value="<?php echo $session->ContactInfo("Mobile1"); ?>" /></td><td><?php echo $form->error("Mobile1"); ?></td>
                        <td>Mobile 2:</td><td><input id="mobile2" name="mobile2" value="<?php echo $session->ContactInfo("Mobile2"); ?>" /></td><td><?php echo $form->error("Mobile2"); ?></td>
                       
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>E-mail 1:</td><td><input id="emailadd" name="emailadd" value="<?php echo $session->ContactInfo("emailadd"); ?>" /></td><td><?php echo $form->error("emailadd"); ?></td>
                        <td>E-mail 2:</td><td><input id="emailadd2" name="emailadd2" value="<?php echo $session->ContactInfo("emailadd2"); ?>" /></td><td><?php echo $form->error("emailadd2"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>Country:</td><td><input id="country" name="country" value="<?php echo $session->ContactInfo("Country"); ?>" /></td><td><?php echo $form->error("Country"); ?></td>
                        <td>Prov/State:</td><td><input id="provstate" name="provstate" value="<?php echo $session->ContactInfo("ProvState"); ?>" /></td><td><?php echo $form->error("ProvState"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>City:</td><td><input id="city" name="city" value="<?php echo $session->ContactInfo("City"); ?>" /></td><td><?php echo $form->error("City"); ?></td>
                        <td>Address:</td><td><input id="address" name="address" value="<?php echo $session->ContactInfo("Address"); ?>" /></td><td><?php echo $form->error("Address"); ?></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                       <td>Postal/Zip:</td><td><input id="postalzip" name="postalzip" value="<?php echo $session->ContactInfo("PostalZipCode"); ?>" /></td><td><?php echo $form->error("PostalZipCode"); ?></td>
                        <td>Notes:</td><td><input id="notes" name="notes" value="<?php echo $session->ContactInfo("Notes"); ?>" /></td><td><?php echo $form->error("Notes"); ?></td>
                        <td>&nbsp;</td><td align="right"><input type="hidden" id="subEditContact" name="subEditContact" value="1" /><input type="hidden" id="tblContactID" name="tblContactID" value="<?php echo $session->ContactInfo("tblContactID"); ?>" /><input type="submit" value="Save" /></td>
                    </tr>
                </table>
          </form>
    Code was added to session.php so that the info would be retrieved and put into the form using, for example,
    Code:
    <?php echo $session->ContactInfo("emailadd"); ?>
    (change emailadd to your field name in the DB that you want to return)
    The function in session.php is called when the server executes the php code in the form on the edit_contact.php page.

    session.php additions:
    at the top:
    Code:
    var $ContactInfo = array();//Contact Information
    then the function

    Code:
      // This should get the info into edit_contact.php    //***************************Added  This*********************************
      function ContactInfo($ID){
         global $database;  //The database connection 
         $this->ContactInfo = $database->getContactInfo($_POST['rowIDCont']);
           return $this->ContactInfo["$ID"];
      }
    later on.

    In database.php we added the function
    Code:
      function getContactInfo(){
          //$q = "SELECT * FROM tblcontact WHERE tblContactID = '$ID'";
         $q = "SELECT * FROM `tblcontact` WHERE `tblContactID`=".$_POST['rowIDCont'];
          $result = mysql_query($q, $this->connection);
          /* Error occurred, return given name by default */
          if(!$result || (mysql_numrows($result) < 1)){
            return NULL;
          }
          /* Return result array */
          $dbarray = mysql_fetch_array($result);
          return $dbarray;
      }
    Then, when you click the Save button on edit_contact.php the process.php updates the database and uses a bookmark to go to go to the spot on the phonebook.php page that you clicked the edit button on originally. This is done using the unique ID field of the contact page table that is used in all of the code tblContactID which is the name of the tag.

    The part I don't understand is why function ContactInfo($ID) has $ID in the ()'s, but perhaps Linchpin311 can explain that.

    Brad
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Mon Mar 30, 2009 5:10 pm

    mbrad wrote:The part I don't understand is why function ContactInfo($ID) has $ID in the ()'s
    this has to do with the argument you pass in a text field's value, like value="<?php echo $session->ContactInfo("LastName"); ?>". Here you are passing the argument "LastName" to the ContactInfo function. From there, that function goes to another function that will query the database and return an array ($dbarray) full of tblcontact's values. After that, we use our supplied argument to return a specific value of that array.

    So as you can see, without the $ID your ContactInfo function would never know to accept an argument and it would try and return the whole array as opposed to a specific value.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Mon Apr 06, 2009 2:31 pm

    Hi Linchpin311,

    Just wondering how I pass the entire array to work with. I have a form I want to build and fill at the same time, and I'd like to use the code you helped me make.

    Any ideas?

    I'm trying variants of:
    Code:
    while($row = mysql_fetch_assoc($session->BudgetInfo($ID)))
        foreach($row as $key => $value) {
          //build form here
        }
    }
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Mon Apr 06, 2009 5:31 pm

    im not exactly sure what you mean by this? the function $session->ContactInfo already returns the whole row from the "tblcontact" table. the argument you send corresponds to a column in that row and then returns you its value.

    explain to me in more detail what you are trying to do and we'll see what we can come up with.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Mon Apr 06, 2009 5:48 pm

    I have a newbudget.php page. On that page I dynamically create a form based on how many categories the user wants to enter info for.

    Example 1: New Budget - I enter 5, as I have 5 categories I want to make a budget on.

    The code then makes a form with 5 rows

    Here is an example of data that could be entered.
    Code:
    Category    Amount    BMY
    Car Pmt      $200      B
    Mortgage    $300      B
    Grocery      $100      B
    Elec        $40        M
    Water        $50        M

    Example 2: New Budget - I enter 3, as I have 3 categories I want to make a budget on.

    The code then makes a form with 5 rows

    Here is an example of data that could be entered.
    Code:
    Category    Amount    BMY
    Gas          $100      Y
    Hotels      $300      Y
    Meals        $100      Y

    So the user then goes to the budget.php page to see all the budgets they've entered. Just like the phonebook.php page there is an Edit button beside each budget incase the user wants to update a budget. So I made an edit_budget.php page, but the form has to be created dynamically based on how many rows are stored for that budget in the db. In Example 1, the code would have to generate a form with 15 <input /> fields 5 rows, 3 per row, then fill it with the info of that budget from the $session code. Example 2 would be 9 <input /> fields 3 rows, 3 per row. I could make a static form with 10 rows and hope that all budgets that users make are equal or less than 10 categories(rows), but that's bad coding.

    So I was hoping to iterate through the results with a foreach loop and generate the form and populate it at the same time.

    Hope that helps.

    Brad
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Mon Apr 06, 2009 7:13 pm

    ok so im assuming your database is set up something like this...

    unique ID
    username who created the budget (so you can tie multiple rows to the same budget)
    category name
    amount
    BMY


    if so, i would just query the database for the username who created the budget. this would return all rows associated with that username. then you can do like
    Code:
    while($row = mysql_fetch_array($result)){

       echo '<p>Category: <input type="text" name="category" value="' . $row['category'] . '"><br>';
       echo 'Amount: <input type="text" name="amount" value="' . $row['amount'] . '"><br>';
       echo 'BMY: <input type="text" name="bmy" value="' . $row['bmy'] . '"></p>';

    }

    that should print out each row thats in the database. hopefully we are on the same page with this. let me know if this is what you were looking for.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Mon Apr 06, 2009 10:30 pm

    I had thought of just putting a query at the top of the page... I just thought that the proper way might be to use the classes. I guess in the end you're writing just as much, if not more code to accomplish the same thing.

    I'll try with the query at the top of the page and let you know how it works out.

    Thanks,

    Brad
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Mon Apr 06, 2009 11:50 pm

    Here is my edit_budget.php page.

    I used 2 queries on the page instead of going with the $session idea we used for the edit_contact.php page.

    Brad

    Code:
    <?php   
    include("MainHeader.php");
    ?>
    <body onLoad="setFocus()">
    <?php   
    include("MainHeader2.php");
    ?>
    <div id="ContentContainer">
    <?php
    /**
     * User has already logged in, so display relavent links, including
     * a link to the admin center if the user is an administrator.
     */
    if($session->logged_in){

             $q = "SELECT `BudgetName`, `Salary`, `Payment1`, `Payment2` FROM `qrybudgetedit` WHERE `tblBudgetID`=".$_POST['rowIDBudget']." LIMIT 1";
               $result = $database->query($q);
             $row = mysql_fetch_assoc($result);
             
             $q2 = "SELECT `Category`, `Amount`, CASE WHEN `BMY`<>'B' THEN CASE WHEN `BMY`='M' THEN 'Monthly' ELSE 'Yearly' END ELSE 'Bi-Weekly' END AS 'BMY' FROM `qrybudgetedit` WHERE `tblBudgetID`=".$_POST['rowIDBudget']."";
               $result2 = $database->query($q2);
             
          ?>   
    <div id="NavContainer" style="width:100%;">
       <ul id="mainmenu">
                    <li><a href="newbudget.php" onmouseover="MoveIconDown('new_messages')"; onmouseout="MoveIconUp('new_messages')";>New Budget<img id="new_messages" class="menuicon" src="images/Post-It_Small.png" /></a></li>
                    <li><a href="budget.php" onmouseover="MoveIconDown('all_messages')"; onmouseout="MoveIconUp('all_messages')";>Budget<img id="all_messages" class="menuicon" src="images/Post-It_Small.png" /></a></li>
       </ul>
        <h3 class="SubTitle">Edit Budget</h3>
    </div>
    <table border="0" cellspacing="0" cellpadding="3" id="NewMessage">
    <tr>
    <td>
    <form action="process.php" method="POST">
        <table>
        <caption>Please enter information in all fields below. Do not use $ when specifying a dollar amount, just enter the number to two decimal places.</caption>
       <tr>
        <td class="title">Budget Name</td>
        <td class="title">Salary</td>
        <td class="title">Payment 1</td>
        <td class="title">Payment 2</td>
        </tr>   
         <tr>
        <td><input id="BudgetName" name="BudgetName" value="<?php echo $row['BudgetName']; ?>" /></td>
        <td><input id="Salary" name="Salary" value="<?php echo $row['Salary']; ?>" /></td>
        <td><input id="Payment1" name="Payment1" value="<?php echo $row['Payment1']; ?>" /></td>
        <td><input id="Payment2" name="Payment2" value="<?php echo $row['Payment2']; ?>" /></td>
        </tr>
       
       
       
        </table>
        <table>
       <tr>
        <td class="title">Budget Line</td>
        <td class="title">Category Name</td>
        <td class="title">$ Amount</td>
        <td class="title">B / M / A</td>
        </tr>

       <?php
            $num=0;
          $numb=1;
          while ($row2 = mysql_fetch_assoc($result2)) {
             //echo "<tr>\n";
             echo "<tr>\n";
             echo "<td>Line ".$numb."</td>\n";
             foreach($row2 as $key2 => $value2) {
                if ($key2<>"BMY") {
                   echo "<td>";
                   echo "<input id=\"New".$key2. "" . $numb . "\" name=\"New".$key2. "" . $numb . "\" value=\"".$value2."\" />";
                   echo "</td>\n";
                } else {
                   echo "<td>";
                   if ($value2=="Bi-Weekly") {
                   echo "<select id=\"NewBMY" . $numb . "\" name=\"NewBMY" . $numb . "\">\n<option value=\"b\">Bi-Weekly</option>\n<option value=\"m\">Monthly</option>\n<option value=\"y\">Yearly</option>\n</select>\n";
                   }
                   elseif ($value2=="Monthly") {
                   echo "<select id=\"NewBMY" . $numb . "\" name=\"NewBMY" . $numb . "\">\n<option value=\"m\">Monthly</option>\n<option value=\"b\">Bi-Weekly</option>\n<option value=\"y\">Yearly</option>\n</select>\n";
                   }
                   else {
                   echo "<select id=\"NewBMY" . $numb . "\" name=\"NewBMY" . $numb . "\">\n<option value=\"y\">Yearly</option>\n<option value=\"b\">Bi-Weekly</option>\n<option value=\"m\">Monthly</option>\n</select>\n";
                   }
                //echo "<input id=\"TheNumRows\" name=\"TheNumRows\" value=\"".$row['NumRows']."\" />";
                   echo "</td>\n";
                }
               }
             echo "</tr>\n";
             $num++;
             $numb++;
          }
           
        ?>
            <tr>
                <td><input type="hidden" id="subCreateBudget" name="subCreateBudget" value="1" /></td>
                <td>&nbsp;</td><td>&nbsp;</td><td><input type="submit" value="Save" /></td>
            </tr>
       
       
       
        </table>
    </form>
    </td>
    </tr>
    </table>

    </div>
    <?php
    }
    else{
    if($form->num_errors > 0){
      echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
    }
    }
    ?>
    </div>
    </div>
    </body>
    </html>
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Fill Form with data

    Post  Linchpin311 on Tue Apr 07, 2009 12:00 am

    you realize using this method makes great use of the database class?

    this looks good! is this working out for you?


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Fill Form with data

    Post  mbrad on Tue Apr 07, 2009 9:16 am

    Ya, it works really well. It took me a bit to get it working exactly the way I wanted, but I'm on my way.

    Yes I did know I'm using the $database class. I guess using the one class is better than not using them at all.

    They way I got the data into the DB in the first place was to use phpMyAdmin. I still haven't been sucessful in getting the data into the db with the .php pages (budget and edit_budget). I don't know how to make a dynamic function that will $_POST[''] all the fields from the dynamically generated form. I have a suggestion from another forum to use arrays, but I haven't figured out how to apply it yet.

    Thanks again,

    Brad

    Sponsored content

    Re: Fill Form with data

    Post  Sponsored content


      Current date/time is Tue Dec 11, 2018 5:17 am