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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Trying to use variable in row resource identifier

    Here's the code - you can probably see what I'm attempting... I want to populate the form fields with the data that matches that field from the client table. I can't seem to get the $fieldfill = $rowclient['".$field."']"; statement to work out... Any suggestions?

    PHP Code:
    $resultclient mysql_query("SELECT * FROM Clients WHERE ClientID = '$GetClientID' ") or die(mysql_error());

    $rowclient mysql_fetch_array$resultclient );

    $result mysql_query("SHOW COLUMNS FROM Clients");

    echo 
    "<form action='edit_process.php'>";

        while (
    $row mysql_fetch_assoc($result)) {
            
    $field $row['Field'];

    $fieldfill $rowclient['".$field."']";

    echo $field."
    : <input type='text' name='".$field."' value='".$fieldfill."' /><br /><br />";
        

    }


    echo "
    </form>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,679
    Thanks
    25
    Thanked 655 Times in 654 Posts
    Try this:

    Code:
    	$field = $row['Field'];
    	$fieldfill = $rowclient["$field"];
    	echo $field.": <input type='text' name=\"$field\" value=\"$fieldfill\" /><br /><br />";
    Pay attention to the quotes.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    HUH???

    NO.

    Code:
    	$field = $row['Field'];
    	$fieldfill = $rowclient[$field]; // NO QUOTES AT ALL
    	echo $field.": <input type='text' name=\"$field\" value=\"$fieldfill\" /><br /><br />";
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,679
    Thanks
    25
    Thanked 655 Times in 654 Posts
    Quote Originally Posted by sunfighter View Post
    Pay attention to the quotes.
    Guess I should.


  •  

    Posting Permissions

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