Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, Currently i have a CGI web page which prints a mySQL search query to the web. However, i want to incorporate a drop down menu which will allow the user to refine the results. I can do this by directing a form to a new script, but i want to recycle the default page. I guess this would use the GET method from the url. But how is this achieved? If anyone could suggest a useful tutorial or point me in the right direction that would be great!
print "Content-type: text/html\n\n"; use DBI; # database information # make connection to database $dbh = DBI->connect($connectionInfo,$userid,$passwd); # prepare and execute query $query = "SELECT * FROM employees ORDER BY lastName, firstName"; $sth = $dbh->prepare($query); $sth->execute(); # assign fields to variables $sth->bind_columns(undef, \$employeeID, \$firstName, \$lastName); print "Employees in the inventory database:<p>"; print "<form action=\"displayResults.pl\" method=post>"; print "<select name=employeeID><option value=\"\">Select an employee</ +option>"; # output employee list to browser as drop-down listings while($sth->fetch()) { print "<option value=$employeeID>$firstName $lastName</option>"; } print "</select><input type=submit name=submit value=submit></form>"; $sth->finish(); #disconnect from database $dbh->disconnect;
Thanks

Replies are listed 'Best First'.
Re: CGI DBI refining results
by pajout (Curate) on Nov 28, 2005 at 11:04 UTC
    Hi, I am not exactly sure what does "drop down menu which will allow the user to refine the results" mean, but, if you want to hack this form to allow editting employees, see html or xhtml specification, to catch graphical possibilities.
    POST method is, imho, better, because it does not limit amount of submited bytes, and, conceptually, submited form data would not be part of url...
    HTML 4.01 Specification
    XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition)
      for the above code example i have selected from the database employees. So with the drop down menu i want to select the employee i want more information about. When submitted instead of directing to a new script i want to print the information to the same page. Therefore, would i need to add to the url the name of the employye so GET/POST can act onit to print info to same screen?
        Consider using the hidden in the form. Then put all the information required in hidden elements (its not displayed in the page so only hide what you don't want seen/changed but want the script to receive). When its submitted you can read that. However, your sending the information in a select to your displayResults.pl file. Only the selected name will be sent, and only items within the specific form (you can have more then one form in an html page and each is individual), so if you want the entire select, you'll have to send each line as a hidden or group them all into one hidden and break them down in the script.
        No, you have not add anything into url explicitly, selected employeeID will be sent automatically to server when submit occurs.
        You can add some if-then-else into your script, to recognize, if posted value of employeeID (value of selected option) is empty or not empty. When empty, you can print current version, when nonempty, you can print detail informations about selected employee.
        Now I see simplicity of your question. If you require only this, you can use <form method="GET">, which is better for debugging...