View Full Version : Resolved Calling value into input box
AdrielGreene
04-09-2009, 08:34 AM
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.
$bgcolor2 = "SELECT bg_color FROM users WHERE user_id={$_SESSION['user_id']}";
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.
AdrielGreene
04-09-2009, 10:59 PM
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.
amutha
04-10-2009, 09:57 AM
You may use this........ Example..........
<?php
$bgcolor="Blue";
?>
<?php
echo "<p><b>Background Color:</b><input type='text' name='bgcolor' size='20' maxlength='20' value='$bgcolor' /></p>";
?>
AdrielGreene
04-10-2009, 10:27 PM
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?
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>";
?>
amutha
04-22-2009, 10:23 AM
check the coding. display the $bgcolordisp value
for example;. give the
echo "$bgcolordisp";
if its display value then
<?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.... :)
AdrielGreene
04-22-2009, 03:09 PM
My error was in the Query.
This works:
<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.
amutha
04-23-2009, 10:24 AM
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. :)
AdrielGreene
04-23-2009, 08:44 PM
Well I cant quite show ALL my code but here is a fair chunk of it.
//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.
amutha
04-24-2009, 10:21 AM
Do you resloved the problem.
do you got the bgcolor in the text box.....:)
AdrielGreene
04-24-2009, 05:28 PM
Resolved: Many thanks
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.