Results 1 to 10 of 10

Thread: Calling value into input box

  1. #1
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Calling value into input box

    I am trying to create code for a user editable CSS which calls information from a MySQL DB. At this point I can UPDATE the value, but I cant seem to SELECT it.

    I would like the user to see the background color they have chosen in the input box before they select a new one. Here are my SELECT and input ECHO.

    Code:
    $bgcolor2 = "SELECT bg_color FROM users WHERE user_id={$_SESSION['user_id']}";
    PHP Code:
    echo '<p><b>Background Color:</b><input type="text" name="bgcolor" size="20" maxlength="20" value="$bgcolor2" /></p>'
    When I log in and go to my edit page the input box displays $bgcolor2.

    I've edited it slightly several times with no success. I'm very sleep deprived and should be home from classes in about 12 hours to post again. Thank you in advance should someone aid me.
    Last edited by Snookerman; 04-23-2009 at 10:59 AM. Reason: added “Resolved” prefix

  2. #2
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    I changed the variable to $bgcolortest for testing so it would not need to access the DB in case something was wrong there.

    $bgcolortest = "Glorious Victory";

    I tried variations of the input form such as:

    <?php ECHO '<p><b>Background Color:</b><input type="text" name="bgcolor" size="20" maxlength="20" value="$bgcolortest" /></p>'; ?>

    and

    <p><b>Background Color:</b><input type="text" name="bgcolor" size="20" maxlength="20" value="<?php ECHO '$bgcolortest' ?>" /></p>

    The response is still the same. The INPUT VALUE shows as $bgcolortest in a browser.

  3. #3
    Join Date
    Apr 2009
    Location
    India
    Posts
    41
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    You may use this........ Example..........
    Code:
    <?php
    $bgcolor="Blue";
    ?>
    <?php
    echo "<p><b>Background Color:</b><input type='text' name='bgcolor' size='20' maxlength='20' value='$bgcolor' /></p>";
    ?>

  4. The Following User Says Thank You to amutha For This Useful Post:

    AdrielGreene (04-10-2009)

  5. #4
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Thanks amutha!
    The $bgcolor doesn't display in the input value anymore, but now it's blank.

    It seems my problem is when I SELECT the value for the variable from MySQL. Can someone grammar check this?

    Code:
    	if (isset($_SESSION['first_name'])) {
    $bgcolorcall = "SELECT bg_color FROM users WHERE user_id={$_SESSION['user_id']}";
    $bgcolordisp = mysqli_query ($dbc, $bgcolorcall) or trigger_error("Query: $bgcolorcall\n<br />MySQL Error: " . mysqli_error($dbc));
    
    <?php
    echo "<p><b>Background Color:</b><input type='text' name='bgcolor' size='20' maxlength='20' value='$bgcolordisp' /></p>";
    ?>

  6. #5
    Join Date
    Apr 2009
    Location
    India
    Posts
    41
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    check the coding. display the $bgcolordisp value
    for example;. give the
    Code:
    echo "$bgcolordisp";
    if its display value then
    Code:
    <?php
    echo "<p><b>Background Color:</b><input type='text' name='bgcolor' size='20' maxlength='20' value='$bgcolordisp' /></p>";
    ?>
    it will be working. if not get $bgcolordisp value. then you have mistake on query or getting the variable or passing the value. verify your code....

  7. The Following User Says Thank You to amutha For This Useful Post:

    AdrielGreene (04-22-2009)

  8. #6
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    My error was in the Query.

    This works:
    Code:
    <p><b>Background Color:</b><input type="text" name="bgcolor" size="20" maxlength="20" value="<?php echo $_display['bg_color']; ?>" /></p>
    I just called it from an array. Works much better in the query process. Thank you Amutha I would have continued to be confused.

  9. #7
    Join Date
    Apr 2009
    Location
    India
    Posts
    41
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    Ok. well, if don't mine, i'll see your code. sent me the full code to my PM or post the code in this forum.

  10. #8
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Well I cant quite show ALL my code but here is a fair chunk of it.

    Code:
    	//if submitted
    if (isset($_POST['submitted'])) {require_once (MYSQL); // From another file to connect to database
    	$professional = $_POST["professional"];
    
    	// Make the update query.
    	$q = "UPDATE users SET professional='$professional' WHERE user_id={$_SESSION['user_id']}";
    	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));}
    
    //filling in the form
    
    require_once(MYSQL); // From another file to connect to database
    $q = "SELECT professional FROM users WHERE user_id={$_SESSION['user_id']}";
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
    $_display = mysqli_fetch_array ($r, MYSQLI_ASSOC);
    ?>
    
    <form action="my_file.php" method="post">
    
    <p><b>Professional Page:</b><textarea name="professional" COLS=40 ROWS=8><?php echo $_display['professional']; ?></textarea></p>
    
    <div align="center"><input type="submit" name="submit" value="Edit my profile" /></div>
    <input type="hidden" name="submitted" value="TRUE" />
    </form>
    This updates fields in the database (for profiles in my case) and then displays them for the user in the same input box. This allows the user to dynamically edit their profile with ease. Once you have a login system it should be easy to implement this code.

  11. #9
    Join Date
    Apr 2009
    Location
    India
    Posts
    41
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    Do you resloved the problem.

    do you got the bgcolor in the text box.....

  12. #10
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Resolved: Many thanks

Bookmarks

Posting Permissions

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