modifying drop-downs

From: Date: Mon, 14 Aug 2000 03:00:56 +0000
Subject: modifying drop-downs
Groups: php.general 
Request: Send a blank email to php-general+get-11549@lists.php.net to get a copy of this message
Hi all, I'm having trouble pulling data from a query result into the drop-downs on the add/modify form. The form is a mix of fill-in CHAR columns and ENUM columns. Add works, the row data returned from the query is right, but the drop-downs reflect the initial value in ENUM and OPTION VALUE, not the actual row info (the CHAR columns populate properly). It's a books database, and the add books form has, along with TITLE and ISBN, drop-downs like BINDING ENUM('paperback','tradepaper','hardcover'), which seem the most sensible type for this. Have I set this up incorrectly? Using PHP 4.0.1pl2, MySQL 3.22.32, SuSE 6.4 Code samples follow... <? # ------------------ # BLcommon.php # common functions # ------------------ ... # --------------------------------------------------- # generate the HTML form to add/change/delete BOOKS # --------------------------------------------------- function generateHTMLform($formvalues, $actionscript, $submitlabel) { printf("<FORM METHOD=post ACTION=\"%s\"><PRE>\n", $actionscript); # -------------- # start fill-ins # -------------- printf("&nbsp;&nbsp;"); printf("<FONT SIZE=3 FACE=helvetica>Title Publisher YrPub"); printf("<BR>"); printf("&nbsp;&nbsp;&nbsp;"); printf("<INPUT TYPE=text SIZE=20 NAME=title VALUE=\"%s\">", ($formvalues) ? $formvalues["title"] : ""); printf("&nbsp;&nbsp;&nbsp;&nbsp;"); printf("<INPUT TYPE=text SIZE=20 NAME=publisher VALUE=\"%s\">", ($formvalues) ? $formvalues["publisher"] : ""); printf("&nbsp;&nbsp;&nbsp;&nbsp;"); printf("<INPUT TYPE=text SIZE=4 NAME=yearpub VALUE=\"%s\">", ($formvalues) ? $formvalues["yearpub"] : ""); printf("<BR>\n"); printf("<BR>\n"); printf("&nbsp;&nbsp;&nbsp;"); ... # ---------------- # start drop-downs # ---------------- printf("<FONT SIZE=3 FACE=helvetica> Category Binding First ed? Signed?"); printf("<BR>"); printf("&nbsp;&nbsp;&nbsp;"); printf("<SELECT NAME=category>", ($formvalues) ? $formvalues["category"] : ""); printf("<OPTION VALUE=literature>literature", ($formvalues) ? $formvalues["category"] : ""); printf("<OPTION VALUE=fiction>fiction", ($formvalues) ? $formvalues["category"] : ""); printf("<OPTION VALUE=non_fiction>non-fiction", ($formvalues) ? $formvalues["category"] : ""); printf("<OPTION VALUE=humor>humor", ($formvalues) ? $formvalues["category"] : ""); printf("<OPTION VALUE=history>history", ($formvalues) ? $formvalues["category"] : ""); printf("<OPTION VALUE=hist_fiction>hist. fiction", ($formvalues) ? $formvalues["category"] : ""); printf("<OPTION VALUE=science>science", ($formvalues) ? $formvalues["category"] : ""); printf("</SELECT>"); printf("&nbsp;&nbsp;&nbsp;"); printf("<SELECT NAME=binding>", ($formvalues) ? $formvalues["binding"] : ""); printf("<OPTION VALUE=paperback>paperback", ($formvalues) ? $formvalues["binding"] : ""); printf("<OPTION VALUE=tradepaper>trade paper", ($formvalues) ? $formvalues["binding"] : ""); printf("<OPTION VALUE=hardcover>hardcover", ($formvalues) ? $formvalues["binding"] : ""); printf("</SELECT>"); ... printf("<INPUT TYPE=submit VALUE=\"%s\">", $submitlabel ); printf("</PRE></FORM>" ); } function returntomain() { printf("<FORM ACTION=\"BLmain.php\" METHOD=post>\n"); printf("<B><FONT COLOR=\"#42426F\"><INPUT TYPE=submit VALUE=\" back to main page \"></B>\n"); printf("&nbsp; &nbsp; &nbsp;"); } ?> -------------------------------------------------- <? #------------------- # BLchange-book.php #------------------- require("BLglobals.php") ; require("BLcommon.php") ; $selectstmt = "SELECT * FROM books WHERE bookid=$bookid" ; #--------------- # connect to db #--------------- if (!($link=mysql_pconnect ($host, $user, $password))) { displayerrmsg(sprintf("error connecting to host %s, by user %s",$host, $user)) ; exit() ; } #----------- # select db #----------- if (!mysql_select_db($dbname, $link)) { displayerrmsg(sprintf("Error in selecting %s database", $dbname)) ; displayerrmsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link))) ; exit() ; } #------------------- # 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", " submit changes... " ); mysql_free_result($result) ; ?>

« previous php.general (#11549) next »