Retreiving data and placing it in a form for editing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Retreiving data and placing it in a form for editing

Post by PastorHank »

Could someone please point me towards a good tutorial on how to most effectively retreive data from my MySql databases and place it in a form for editing. I've done a search and maybe I just don't know how to phrase it, but I don't really see anything.

Thank you
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

1) Connect to your database

2) Get the data you want

Code: Select all

$query="SELECT * from database_table WHERE criteria_is_met"; //make a query that will return one result from the mysql database
$result=mysql($query)or DIE ("Couldn't get a result");//do the search
$row=mysql_fetch_assoc($result);//put the result into an associative array
Output to a form

Code: Select all

echo "<form action=\"processpage.php\" method=post>";
echo "<input type=text name=whatever value=\"$row[whatever]\"><br>";//puts the data from column whatever into a text box for editing, must be double quoted or only one word will appear!
echo "<textarea name=whatever1>$row[whatever1]</textarea><br>"; //puts the data from whatever1 column into a textarea box for editing
echo "<input type=submit value=submit></form>";
The hard bit is working out what $query should contain to access one line of data from the database
Try googling "mysql select tutorial" there are plenty around!
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

thank you
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

I've got most of it working except for being able to put data into a drop-down box.

I select all the data and then

Code: Select all

echo "<form action='cgi-bin/getprocesstoedit.php' method=post>"; 
echo "<select name='fawnlist'>";

 while ($row = mysql_fetch_array($result)) {
  extract($row);
  	 echo "<option value=$row[deernumber]><br>\n";
}
echo "</select>";
echo "<input type=submit value=submit>";
echo "</form>";
Gives me the drop down, but no data. there's no filter on the data, so all records should be showing up.
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

Never mind, I got it....I had the wrong syntax for the option statement
Post Reply