Forum Moderators: coopster

Message Too Old, No Replies

Only one word displaying in textbox

php textbox one word

         

indiguy

4:56 am on Aug 26, 2009 (gmt 0)

10+ Year Member




Hi, im retriving text from a database field. But its only showing the first word despite increasing the box size.
Im new to php, and the db is mysql.
Ive tried, and searched internet with no good results.

Can anyone help please?

some of my code:

while ( $row = mysql_fetch_array($result) )

echo .. <input type='text' name='description' value=".$row[tea_choice].">
...

brotherhood of LAN

5:04 am on Aug 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to the forums indigoguy,

You might want to try:

<input type='text' name='description' value=".htmlentities($row[tea_choice]).">

If there is a " character in your variable, it would otherwise close the attribute in the HTML you're trying to place the value into.

htmlentities [us2.php.net] converts all applicable characters to HTML entities

indiguy

5:47 am on Aug 26, 2009 (gmt 0)

10+ Year Member



Sorry, but no luck. The final result of this code is so the db field can be edited from the webpage frontend.
So i can only see that a textbox is the only possible way..

this is my code:

$result = mysql_query("select * from cp_teas"); //query the database

if (!$result) //error check
{
echo("<P>Error performing query:".mysql_error() );
exit();
}

echo ("<table>");
echo ("<tr align=center>");
echo ("<th>Choice</th>");
echo ("<th>Decription</th>");
echo ("<th>Price</th>");
echo ("<th>Order</th>");
echo ("</tr>");
while ( $row = mysql_fetch_array($result) ) //return results line by line
{
echo ("<tr>");
echo "<td> <form><input type='text' name='choice' value=".$row[tea_choice]"></td>";
echo "<td> <form><input type='text' name='descrtiption' value=".$row[tea_desc]."></td>";
echo "<td> <form><input type='text' name='price' value=".$row[tea_price]."></td>";

}
echo ("</table></center>");
?>

brotherhood of LAN

6:40 am on Aug 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A trial and error check method would be to try this

while ( $row = mysql_fetch_array($result) ) //return results line by line
{
print_r($row);
CONTINUE;
}
exit(0);

If the variables look OK, then you can assume it's the PHP or the HTML formatting that's causing problems.

The HTML you supplied may cause problems, You might want to put the beginning of your <form> when you output <table> and close it along with the table after the while loop. You included <form> within each row of the MySQL output, which would cause problems later on when you're trying to update the database.

Habtom

6:44 am on Aug 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<input type='text' name='description' value='". $row[tea_choice] ."'>

indiguy

9:43 am on Aug 26, 2009 (gmt 0)

10+ Year Member



thank you so much.. mmmm programming grammer does it everytime..
i see i forgot the " ' "

indiguy

2:25 am on Aug 28, 2009 (gmt 0)

10+ Year Member



hi, i have a new question ive been working on:
I have 4 options from buttons in php page.
i want to be able to click on a button then run the variable to query the db, and if another button is clicked, then the variable relating to that is queried etc...

Can it be done?

eg:
$menu1 = mysql_query("..."); //query the database tea table
$menu2 = mysql_query("...");

echo "<td>"."<input type='button' value='Teas' name='button1' onclick='".$menu1."'></td>";//
echo "<td><input type='button' value='Platters' name='button2' onclick='".$menu2."'></td>";//

if ($menu1) {...}
if ($menu2) {...}