Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Location
    Here
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy How do I fill textboxes?

    I have a page which uses a session_user_id from
    Code:
    if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) {
    header("location: login.php");
    to get a row of record from a table to populate textboxes on a page

    I understand the query to fish out the row is
    Code:
    mysql_query("SELECT CName, CAddress, CEmail,... FROM customer WHERE CuserID = '$_SESSION['SESS_MEMBER_ID']'")
    But how do I fill the textboxes? Do I really need a different query for every textbox, or can I use $_GET/POST?

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Posts
    118
    Thanks
    3
    Thanked 9 Times in 9 Posts
    PHP Code:
    <?php

    //connection

    $result mysql_query("SELECT CName, CAddress, CEmail,... FROM customer WHERE CuserID = '$_SESSION['SESS_MEMBER_ID']'");

    while(
    $row=mysql_fetch_array($result))
    {
    ?>
    Name: <input type='text' name='cname' value='<?php echo $row['CName']; ?>'>";

    Address: <input type='text' name='caddress' value='<?php echo $row['CAddress']; ?>'>";

    // same for all text boxes...

    <?php
    }
    ?>

    If it's only one row of data, then the while loop isn't even necessary. Just set $row=mysql_fetch_array($result) and print the rows out like I did and remove the brackets.
    Last edited by peteyb383; 05-21-2008 at 09:24 PM.

  • Users who have thanked peteyb383 for this post:

    Oahgneg (05-21-2008)

  • #3
    New to the CF scene
    Join Date
    Apr 2008
    Location
    Here
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I apologise, but it seems like I made a boo-boo

    1 of them isnt a textbox, but a dropdown list
    Code:
    <select name="country" id="country">
    <option value="Australia">Australia</option>
    <option value="Canada">Canada</option>
    <option value="United States">United States</option>
    so how do I fetch the Country from the $row=mysql_fetch_array($result) & make it the selected value in the dropdown list?

  • #4
    Regular Coder
    Join Date
    Mar 2008
    Posts
    118
    Thanks
    3
    Thanked 9 Times in 9 Posts
    You can do this:

    PHP Code:

    $country = $row['country'];

    <select name="country" id="country">
    <option value="Australia" <?php echo ($country == 'Australia'"selected" "");?>>Australia</option>
    <option value="Canada" <?php echo ($country == 'Canada'"selected" "");?>>Canada</option>
    <option value="United States" <?php echo ($country == 'United States'"selected" "");?>>United States</option>
    </select>
    Might be an easier way, but it is slipping my mind

  • #5
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    I am not a php guru but I think you may be able to do it in either the while loop or (if there is such a thing in php), a 'for' loop.

    Someone else should be along soon to show the correct syntax but try something along the lines of

    Code:
    <select name="country" id="country"> 
    
    <?php
    
    //connection
    
    $result = mysql_query("SELECT CName, CAddress, CEmail,... FROM customer WHERE CuserID = '$_SESSION['SESS_MEMBER_ID']'");
    
    while($row=mysql_fetch_array($result))
    {
    ?>
    <option value="$row">$row</option>
    <?php
    }
    ?>
    
    </select>
    hth

    bazz
    Last edited by bazz; 05-22-2008 at 12:02 AM.

  • #6
    Regular Coder
    Join Date
    Mar 2008
    Posts
    118
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by bazz View Post
    I am not a php guru but I think you may be able to do it in either the while loop or (if there is such a thing in php), a 'for' loop.

    Someone else should be along soon to show the correct syntax but try something along the lines of
    I think his/her table only has one country per member, and he/she wants it selected within a select group.

    So the whole list of countries would be there, and their specific one would be selected with my code. Yours would simply set it as an option.

  • #7
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Quote Originally Posted by Oahgneg View Post

    1 of them isnt a textbox, but a dropdown list
    Code:
    <select name="country" id="country">
    <option value="Australia">Australia</option>
    <option value="Canada">Canada</option>
    <option value="United States">United States</option>
    OK, I just read this and thought my response might be of help.

    bazz

  • #8
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    For much cleaner forms, you might want to rip out the write_form_variables() function here [ANNC] New PHP FAQ
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •