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

Populating an html form with php

P: 4
Hello I wanted to follow on from http://bytes.com/forum/thread3085.html but the forum wouldn't let me post ... so ...

I dont see the complete answer. If this is how to get variables from php into html text fields

Expand|Select|Wrap|Line Numbers
  1. $foo = "something from db"
  2. $bar = "something very long from db"
  3.  
  4. ...
  5. <input type="text" name="short" value="$foo">
  6. <textarea name="long">$bar</textarea>
How do you get the data into the variables?

Do I start my html with say, this:
Expand|Select|Wrap|Line Numbers
  1. <FORM METHOD=POST ACTION="annuaire_populate.php">
then in the php file:
something like

* connect to the database and table and then

Expand|Select|Wrap|Line Numbers
  1. $foo= 'SELECT * FROM $table';
Thanks in advance
Oct 28 '08 #1
Share this Question
Share on Google+
3 Replies


zabsmarty
P: 25
hello,
please change these
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="short" value="$foo">
  2. <textarea name="long">$bar</textarea>
into

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="short" value="<?php echo $foo;?>">
  2. <textarea name="long"><?php echo $bar;?></textarea>
Oct 28 '08 #2

Markus
Expert 5K+
P: 6,050
hello,
please change these
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="short" value="$foo">
  2. <textarea name="long">$bar</textarea>
into

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="short" value="<?php echo $foo;?>">
  2. <textarea name="long"><?php echo $bar;?></textarea>
Zab, start using code tags please.
Oct 28 '08 #3

Atli
Expert 5K+
P: 5,058
Hi.

I'm not sure I fully understand your problem.

Are you trying to get data from your database into your form?
If that is the case, then simply printing them into the HTML would do the trick.
For example:
Expand|Select|Wrap|Line Numbers
  1. $db = mysqli_connect("localhost", "usr", "pwd", "test");
  2. $result = mysqli_query($db, "SELECT data FROM table");
  3.  
  4. echo '<form action="processPage.php" method="post">
  5. while($row = mysqli_fetch_assoc($result)) {
  6.   echo '<input type='text' name='box[]' value='". $row['data'] .'" /><br />';
  7. }
  8. echo '<input type="submit" />
  9. echo '</form>';
  10.  
Which would send all the boxes into the "processPage.php" as an array.

Or are you trying to get data from your HTML form into your PHP script?
If that is the case, then check out this article.

And please use [code] tags when posting your code examples!
Thank you.
Oct 28 '08 #4

Post your reply

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