By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,990 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,990 IT Pros & Developers. It's quick & easy.

Retrieving data from database and displaying in textbox/text area

vikas1111
100+
P: 122
Hi All


Can anyone give me an idea to solve the problem.. My Problem is ,, I want to Retrieving data from database and displaying in textbox... If anybody have link of some good tutorial on this pls let me know..Or if anybody can explain I would be very thankful...
May 29 '08 #1
Share this Question
Share on Google+
10 Replies


100+
P: 310
You are asking a very general basic question, and I believe this forum tries to help with more specific problems. But to get you started, let us assume you wish to use PHP on the server side to interact with your database and then produce HTML output to send to the user's browser. And the database values are to be shown in the forms in the page that the HTML produces in the user's browser.

So you need to know how to invoke a PHP script on the server, how to get the PHP script to connect to your database, how to do a "select" query to get the data you want out of the database table or tables, how to then put those values into PHP variables which then can be outputted in the HTML that will produce the page. So you also need to know how to produce the HTML with the forms that you want, and how to place the PHP variables that came from the database into the forms in the proper place rather than just "hard coding" static variables there.

Just take the above one at a time and look at some documentations for PHP, SQL, HTML, etc.
May 29 '08 #2

vikas1111
100+
P: 122
Thanks coolsti

How to place the PHP variables that come from the database into the forms in the proper place .i.e. in txt box or txt area...


I just want to know obout the above line....Other things i know..
May 29 '08 #3

rpnew
100+
P: 188
Hi All


Can anyone give me an idea to solve the problem.. My Problem is ,, I want to Retrieving data from database and displaying in textbox... If anybody have link of some good tutorial on this pls let me know..Or if anybody can explain I would be very thankful...
Hi,
I've seen your last post regarding inserting data problem so i guess you know how to use PHP to get data.. and put it them into variable. So you can simple do the following to display it in the text box...
1.
[PHP]
<?php
//your php code for fetching data and geting them into variable
?>

<input type="text" name="xyz" value=<?php echo $val; ?> >
[/PHP]
or
2.
[PHP]
<?php
//your php code for fetching data and geting them into variable

echo "<input type=\"text\" name=\"xyz\" value='$val'>";
[/PHP]

You can use either of the way... just be careful with escaping " in second example..

This is not related to your problem exactly but you may find this
thread useful for comparision for above two ways
May 29 '08 #4

vikas1111
100+
P: 122
Hi,
I've seen your last post regarding inserting data problem so i guess you know how to use PHP to get data.. and put it them into variable. So you can simple do the following to display it in the text box...
1.
[PHP]
<?php
//your php code for fetching data and geting them into variable
?>

<input type="text" name="xyz" value=<?php echo $val; ?> >
[/PHP]
or
2.
[PHP]
<?php
//your php code for fetching data and geting them into variable

echo "<input type=\"text\" name=\"xyz\" value='$val'>";
[/PHP]

You can use either of the way... just be careful with escaping " in second example..

This is not related to your problem exactly but you may find this
thread useful for comparision for above two ways

Thanks

I am trying tp do in this way but its not working..


[PHP]
while($row = mysql_fetch_array($result))
{
echo "<input type="text" name="txtname" value='$row['id']'>";
}
[/PHP]


Connection and mysql syntax are correct..Only problem in displaying in textbox..

I am getting proper output to the bellow code...
[PHP]

while($row = mysql_fetch_array($result))
{
echo "<td>" . $row['id'] . "</td>";
}

[/PHP]
May 29 '08 #5

rpnew
100+
P: 188
Thanks

I am trying tp do in this way but its not working..


[PHP]
while($row = mysql_fetch_array($result))
{
echo "<input type="text" name="txtname" value='$row['id']'>";
}
[/PHP]


Connection and mysql syntax are correct..Only problem in displaying in textbox..

I am getting proper output to the bellow code...
[PHP]

while($row = mysql_fetch_array($result))
{
echo "<td>" . $row['id'] . "</td>";
}

[/PHP]
First tell me what are you geting as output...

second thing i guess you need to escape your ' into your example like this... try this..
[PHP]
echo "<input type="text" name="txtname" value='$row[\'id\']'>";

[/PHP]

Regards,
RP
May 29 '08 #6

vikas1111
100+
P: 122
I have created a table in mysql database to insert some records say students or employee records.. Now what i have to do is i have to display all the records in admin view page..( which i have done).. There is an option provided for editing the records beside every record.. So when the admin clicks on the edit button another form should open which will contain information of the user in the text box so that he can just edit and save the changes back into the databse..

This is a part of what i have coded..

[PHP]
include("connection.php");
$result = mysql_query("SELECT * FROM usttable");
while($row = mysql_fetch_array($result))
{
echo "<input type="text" name="txtname" value='$row[\'id\']'>";
}

[/PHP]
May 29 '08 #7

rpnew
100+
P: 188
I have created a table in mysql database to insert some records say students or employee records.. Now what i have to do is i have to display all the records in admin view page..( which i have done).. There is an option provided for editing the records beside every record.. So when the admin clicks on the edit button another form should open which will contain information of the user in the text box so that he can just edit and save the changes back into the databse..

This is a part of what i have coded..

[PHP]
include("connection.php");
$result = mysql_query("SELECT * FROM usttable");
while($row = mysql_fetch_array($result))
{
echo "<input type="text" name="txtname" value='$row[\'id\']'>";
}

[/PHP]
Hi,
can you be a little more specific.. i guess i'm a bit confused with what you exactly want... i mean are you getting any error or you are asking how do i do that?

Regards,
RP
May 29 '08 #8

vikas1111
100+
P: 122
<input type="text" name="text1" value="<?php echo $row["usr_password"]; ?>">

This line I was searching for .....


THANKS
May 29 '08 #9

rpnew
100+
P: 188
<input type="text" name="text1" value="<?php echo $row["usr_password"]; ?>">

This line I was searching for .....


THANKS
welcome,
Glad that you found solution.
come back whenever you have problem.

Regards,
RP
May 29 '08 #10

vikas1111
100+
P: 122
welcome,
Glad that you found solution.
come back whenever you have problem.

Regards,
RP

Sure RP Thanks once again..
May 29 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.