modifying data

From: Date: Sat, 12 Aug 2000 01:31:41 +0000
Subject: modifying data
Groups: php.db 
Request: Send a blank email to php-db+get-1987@lists.php.net to get a copy of this message
Hi all, I'm building a DB to keep track of my books. add/search/del all work fine, but I'm stuck on modifying option fields. For the table books, there are fill-ins for title, isbn etc, but category, binding etc are option items. The problem is pulling that data onto the modify form (same as for adding a record) from the results of the query. The fill-in fields populate fine, but the option boxes don't (and I've confirmed that the data's there) and, if not reset to the proper options, default to the first of n choices. Some code: ... #--------------------------------------------------- # generate the HTML form to add/change/delete BOOKS #--------------------------------------------------- function generateHTMLform($formvalues, $actionscript, $submitlabel) { printf("<FORM METHOD=post ACTION=\"%s\"><PRE>\n", $actionscript); printf("<FONT SIZE=3 FACE=helvetica>Title Publisher YrPub</FONT> <INPUT TYPE=text SIZE=20 NAME=title VALUE=\"%s\">", ($formvalues) $formvalues["title"] : ""); printf("<FONT SIZE=4> </FONT> <INPUT TYPE=text SIZE=20 NAME=publisher VALUE=\"%s\">", ($formvalues) ? $formvalues["publisher"] : ""); printf("<FONT SIZE=4> </FONT> <INPUT TYPE=text SIZE=4 NAME=yearpub VALUE=\"%s\">", ($formvalues) ? $formvalues["yearpub"] : ""); ?> <HTML> <BODY> <FONT SIZE=3 FACE=helvetica> Category Binding</FONT> <SELECT NAME="category"> <OPTION VALUE="literature">literature</OPTION> <OPTION VALUE="history">history</OPTION> <OPTION VALUE="hist_fiction">hist. fiction</OPTION> <OPTION VALUE="science">science</OPTION> <OPTION VALUE="humor">humor</OPTION> <OPTION VALUE="fiction">fiction</OPTION> <OPTION VALUE="nonfiction">nonfiction</OPTION> <OPTION VALUE="reference">reference</OPTION> </SELECT> <SELECT NAME="binding"> <OPTION VALUE="paperback">paperback</OPTION> <OPTION VALUE="tradepaper">trade paperback</OPTION> <OPTION VALUE="hardcover">hardcover</OPTION> </SELECT> ... <? Here's what's invoked when I choose CHANGE from the query results. It displays current values (except for those pesky option lists) for modification. #------------------- # BLchange-book.php #------------------- require("BLglobals.php") ; require("BLcommon.php") ; $selectstmt = "SELECT * FROM books WHERE bookid=$bookid" ; #--------------- # connect to db #--------------- ... #----------- # select db #----------- ... #------------------- # execute the query #------------------- if (!($result= mysql_query($selectstmt, $link))) { displayerrmsg(sprintf("Error in executing %s stmt", $selectstmt)) ; displayerrmsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link))) ; exit() ; } generateHTMLheader("please make any desired changes...") ; if (!($row = mysql_fetch_object($result))) { displayerrmsg("Internal error: the entry does not exist") ; exit() ; } $resultentry["bookid"] = $row->bookid; $resultentry["title"] = $row->title; $resultentry["publisher"]= $row->publisher; $resultentry["yearpub"]= $row->yearpub; $resultentry["isbn"]= $row->isbn; $resultentry["yearpurch"]= $row->yearpurch; $resultentry["pricepaid"]= $row->pricepaid; $resultentry["comments"]= $row->comments; $resultentry["category"]= $row->category; $resultentry["binding"]= $row->binding; $resultentry["first_ed"]= $row->first_ed; $resultentry["signed"]= $row->signed; $resultentry["bookcondition"]= $row->bookcondition; $resultentry["dj_condition"]= $row->dj_condition; generateHTMLform( $resultentry, "BLupdate-book.php?bookid=$bookid", " enter changes... " ); mysql_free_result($result) ; ?> I think I'm screwing up in that the option boxes are strictly in HTML, but I can find no examples suggesting how to handle them with PHP or to somehow have the option column data appear. I've tried the MySQL columns as both ENUMs and as CHAR fields, and that seems to have no effect. Help? Suggestions? Alternate approach? Location of bridge to jump from? TIA, curt

« previous php.db (#1987) next »