Page 1 of 1

Retreiving data and placing it in a form for editing

Posted: Mon Jul 03, 2006 8:03 am
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

Posted: Mon Jul 03, 2006 9:04 am
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!

Posted: Mon Jul 03, 2006 9:23 am
by PastorHank
thank you

Posted: Mon Jul 03, 2006 10:20 am
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.

Posted: Mon Jul 03, 2006 10:48 am
by PastorHank
Never mind, I got it....I had the wrong syntax for the option statement