im Ivica and im new here.
i need form with 5 places for product codes. Every product have 4 rows (name, perex, amount, library_id) in database and i want place solution every products to different places.
Can help?
Sorry for my english.
DB CODE:
<?php
$mysqli = new mysqli('localhost', 'user', 'pass', 'db');
if ($mysqli->connect_error) {
die('Nepodařilo se připojit k MySQL serveru (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
$sql = $mysqli->query("SELECT library_id, amount, name, perex, extId
FROM product_item, main_library, product_item_price, product_text
WHERE product_item.product_id = main_library.main_id
AND product_item.id = product_item_price.item_id
AND product_item.product_id = product_text.product_id
AND product_item_price.level_id = 1 AND product_item.extId = '$test'");
echo 'Z databaze jsme ziskali ' . $sql->num_rows . ' radku.';
echo "</br>";
while ($produkt = $sql->fetch_assoc())
{
printf($produkt['name']);
echo "</br>";
printf($produkt['perex']);
echo "</br>";
printf($produkt['amount']);
echo "</br>";
}
$sql->free_result();
$mysqli->close();
?>
Example: I use form and try find 3 different products and these "name", "perex" and "amount" by ID and need to put those results in some tables with any places on page.
FORM:
<form action="search.php" method="REQUEST">
<b>Find product:</b>
<input type="text" name="productID" size="50">
<input type="text" name="productID2" size="50">
<input type="text" name="productID3" size="50">
<br>
<input type="submit" value="Search"> </form>
TABLE:
<table>
<tr>
<td>productID name</td>
<td>productID name</td>
<td>productID name</td>
<tr>
<tr>
<td>productID2 perex</td>
<td>productID2 perex</td>
<td>productID2 perex</td>
<tr>
<tr>
<td>productID3 amount</td>
<td>productID3 amount</td>
<td>productID3 amount</td>
<tr>
</table>
MYSQL look this:
$sql = $mysqli->query("SELECT library_id, amount, name, perex, extId
FROM product_item, main_library, product_item_price, product_text
WHERE product_item.product_id = main_library.main_id
AND product_item.id = product_item_price.item_id
AND product_item.product_id = product_text.product_id
AND product_item_price.level_id = 1
AND (product_item.extId = '$_REQUEST[productID]'
OR product_item.extId = '$_REQUEST[productID2]'
OR product_item.extId = '$_REQUEST[productID3]')");
Can help?
Ivica
Related
I'm trying to echo out a series of rows from MySQL database using mysql_fetch_array while loop into a table with form. I tried not to repeat the form-table and /table-/form tag but only repeat tr.../tr tag while echoing.
Although, it is also repeating form-table and /table-/form tags.
Can anybody please help. I just want tr.../tr to be repeated.
Below is the code:
$topmessage = '<form><table width="100%" border="0" cellspacing="0" cellpadding="10">';
$bottommessage = '</table><div align="right"><input type="submit" name="approveimage" value="Approve" /><input type="submit" name="disapproveimage" value="Disapprove" /></div></form>';
$multirowing = '';
require("../connect.php");
$query2 = "SELECT * FROM imagegallery WHERE approve ='0'";
$result2 = mysql_query($query2);
while($rowphew = mysql_fetch_array($result2))
{
$multirowing .= '<tr>
<td>' . $rowphew['username'] . '</td>
<td>
<a href="uploads/' . $rowphew['image'] . '">
<img src="uploads/' . $rowphew['image'] . '" width="100px" />
</a>
</td>
<td>
<input type="checkbox" name="selectingimage" value="' . $rowphew['image'] . '" />
</td>
</tr>';
}
$message = $topmessage . $multirowing . $bottommessage;
echo $message;
The outcome result (as shown in source code) given is: (sorry cant upload image as need 10 reputation points..ahh)
<form><table>
<tr><td>Image1</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
<tr><td>Image3</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
<tr><td>Image3</td></tr>
<tr><td>Image4</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
<tr><td>Image3</td></tr>
<tr><td>Image4</td></tr>
<tr><td>Image5</td></tr>
</table>BUTTONS</form>
You need to append strings to $multirowing, not to replace it. And you should use htmlentities.
$topmessage = '<form><table width="100%" border="0" cellspacing="0" cellpadding="10">';
$bottommessage = '</table><div align="right"><input type="submit" name="approveimage" value="Approve" /><input type="submit" name="disapproveimage" value="Disapprove" /></div></form>';
$multirowing = '';
require("../connect.php");
$query2 = "SELECT * FROM imagegallery WHERE approve ='0'";
$result2 = mysql_query($query2);
while($rowphew = mysql_fetch_array($result2))
{
$multirowing .= '<tr>
<td>' . htmlentities($rowphew['username']) . '</td>
<td><img src="uploads/' . htmlentities($rowphew['image']) . '" width="100px" /></td>
<td>
<input type="checkbox" name="selectingimage" value="' . htmlentities($rowphew['image']) . '" />
</td>
</tr>';
}
$message = $topmessage . $multirowing . $bottommessage;
echo $message;
Aside from the fact the msql_query has been deprecated (you should beter move to PDO).
You're setting $multirowing = '<tr>....'
I think you want this changed to $multirowing .= '<tr>....'
Is this inside another loop?
the MySQL command that I am running is not updating the database. I have an image of the database in the image below showing all the various data fields (i.e. tokens).
Here is the code that is supposed to make a successful update but doesnt for some strange reason:
<?php
include('dbcategory.php');
$name_1 = "";
$institution_1 = "";
$instaddress_1 = "";
$monthto_1 = "";
$toyear_1 = "";
$monthto_1_1 = "";
$toyear_1_1 = "";
$graduate_1 = "";
$averages_1 = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$idz = $_POST['idz'];
$full_name = $_POST['full_name'];
$name_1 = $_POST['name_1'];
/* echo $name_1; echo $full_name; */
$institution_1 = $_POST['institution_1'];
$instaddress_1 = $_POST['instaddress_1'];
$monthto_1 = $_POST['monthto_1'];
$toyear_1 = $_POST['toyear_1'];
$monthto_1_1 = $_POST['monthto_1_1'];
$toyear_1_1 = $_POST['toyear_1_1'];
$graduate_1 = $_POST['graduate_1'];
$averages_1 = $_POST['averages_1'];
$query12 = "UPDATE education SET `full_name`=?, `name_1`=?,`institution_1`=?,`instaddress_1`=?,`monthto_1`=?,`toyear_1`=?,`monthto_1_1`=?, `toyear_1_1`=?, `graduate_1`=?, `averages_1`=? WHERE `idz`=?";
$bb = $dbs->prepare($query12);
$bb ->execute(array($full_name, $name_1, $institution_1, $instaddress_1, $monthto_1, $toyear_1, $monthto_1_1, $toyear_1_1, $graduate_1, $averages_1, $idz));
}
/* if (isset($_SERVER["HTTP_REFERER"])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
*/
?>
Here's the code for the forms that do the updating:
<?php
//Edit a product
//Input:
// id: id number of the product to edit. GET.
//Path from this page to the site root.
//Title of this page.
include('dbcategory.php');
//Fetch product data.
$idz = $_GET['idz'];
//$full_name = $_GET['full_name'];
$query = "SELECT * FROM education WHERE idz ='$idz'";
$record_set = $dbs->prepare($query);
$record_set -> execute();
$row = $record_set->fetch(PDO::FETCH_ASSOC);
$idz = $row['idz'];
$full_name = $row['full_name'];
$name_1 = $row["name_1"];
$institution_1 = $row["institution_1"];
$instaddress_1 = $row["instaddress_1"];
$monthto_1 = $row["monthto_1"];
$toyear_1 = $row["toyear_1"];
$monthto_1_1 = $row["monthto_1_1"];
$toyear_1_1 = $row["toyear_1_1"];
$graduate_1 = $row["graduate_1"];
$averages_1 = $row["averages_1"];
/*
*session start;
* dis is a session array;
* i is a session variable;
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body
{
background-image:url('../banner.jpg');
background-repeat:no-repeat;
background-position: center center;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<html>
<body>
<br><br><br>
<H2 align="center"><u>EDIT <?php print $name_1;?> </u></H2>
<form id="myform1" action="save-edited-applications.php" method="post">
<div id="div2">
<table border="1" align="center" cellspacing="0" style="margin-top:22px width="900"">
<colgroup>
<col span="1">
</colgroup>
<tr>
<td valign="top"><label for="name" size="3"> <font size="3">Name of Institution</font></label></td>
<td valign="top"><label for="institution" size="3"><font size="3">Type of Institution </font></label></td>
<td valign="top"><label for="instaddress" size="3"> <font size="3">Address</font></label></td>
<td valign="top"><label><font size="3">From</font></label></td>
<td valign="top"><label> <font size="3">To </font> </label></td>
<td valign="top"><label><font size="3">From</font></label></td>
<td valign="top"><label> <font size="3">To </font> </label></td>
<td valign="top"><label for="graduate" size="3"> Did You <br> Graduate?</label></td>
<td valign="top"><label for="averages"> Average <br>Grade</label></td>
<th>Save</th>
</tr>
<td valign="top">
<input type="hidden" id="idz" name="idz[]">
<input type="hidden" id="full_name" name="full_name[]">
<input type="text" name="name_1[]" id="name_1"
value="<?php print $name_1; ?>"> </td>
<td valign="top"><select name="institution_1[]" id="institution_1" >
<option <?php if(isset($_POST['institution'])) { echo $_POST['institution']; } ?>><?php print $institution_1; ?></option>
<?php
$sql1a = "SELECT * FROM institution ORDER BY institution asc";
$smt1a = $dbs->prepare($sql1a);
$smt1a -> execute();
while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
{
if($row1a['institution']==$_GET['id3'])
echo("<option selected value='$row1a[institution]'>$row1a[institution]</option>");
else
echo("<option value='$row1a[institution]'>$row1a[institution]</option>");
}
?>
</select></td>
<td valign='top'><input type="text" name="instaddress_1[]" id="instaddress_1" size="30"
value="<?php print $instaddress_1; ?>"></td>
<td valign='top'><select name='monthto_1[]' id='monthto_1'> <option><?php print $monthto_1; ?></option>
<?php
$sql1a = "SELECT * FROM month ORDER BY id";
$smt1a = $dbs->prepare($sql1a);
$smt1a -> execute();
while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
{
if($row1a['month']==$_GET['id6'])
echo("<option selected value='$row1a[month]'>$row1a[month]</option>");
else
echo("<option value='$row1a[month]'>$row1a[month]</option>");
}
?></select></td>
<td valign='top'><select name='toyear_1[]' id='toyear_1'> <option><?php print $toyear_1; ?></option>
<?php
$sql1a = "SELECT * FROM year ORDER BY year desc";
$smt1a = $dbs->prepare($sql1a);
$smt1a -> execute();
while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
{
if($row1a['year']==$_GET['id7'])
echo("<option selected value='$row1a[year]'>$row1a[year]</option>");
else
echo("<option value='$row1a[year]'>$row1a[year]</option>");
}
?></select></td>
<td valign='top'><select name='monthto_1_1[]' id='monthto_1_1'> <option><?php print $monthto_1_1; ?></option>
<?php
$sql1a = "SELECT * FROM month ORDER BY id";
$smt1a = $dbs->prepare($sql1a);
$smt1a -> execute();
while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
{
if($row1a['month']==$_GET['id6'])
echo("<option selected value='$row1a[month]'>$row1a[month]</option>");
else
echo("<option value='$row1a[month]'>$row1a[month]</option>");
}
?></select></td>
<td valign='top'><select name='toyear_1_1[]' id='toyear_1_1'> <option><?php print $toyear_1_1; ?></option>
<?php
$sql1a = "SELECT * FROM year ORDER BY year desc";
$smt1a = $dbs->prepare($sql1a);
$smt1a -> execute();
while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
{
if($row1a['year']==$_GET['id7'])
echo("<option selected value='$row1a[year]'>$row1a[year]</option>");
else
echo("<option value='$row1a[year]'>$row1a[year]</option>");
}
?></select></td>
<?php if($graduate_1=="yes"){
echo "<td valign='top'>Yes<input type='checkbox' id='graduate_1' name='graduate_1[]' onclick='cleardata2(this)' value='$graduate_1' checked> No
<input type='checkbox' id='graduate_1' name='graduate_1[]' onclick='cleardata3(this)' value='no' disabled> </td>";
}
if($graduate_1=="no"){
echo "<td valign='top'>Yes<input type='checkbox' id='graduate_1' name='graduate_1[]' onclick='cleardata2(this)' value='yes' disabled> No
<input type='checkbox' id='graduate_1' name='graduate_1[]' onclick='cleardata3(this)' value='$graduate_1' checked> </td>";
}
?>
<td valign='top'><input type="text" name="averages_1[]" id="averages_1" value="<?php print $averages_1; ?>"></td>
<td valign='top'><button type="Submit" name="Save">Save</button></td>
</div>
</form>
</table>
<a href="origin.php" >BACK </a>
</body>
</html>
The image below shows the form to the code above:
The code runs and executes just fine without any errors in it - including the syntax or logic - but it fails to make any updates to the database tables. The tokens are in correct order. Why is not updating correctly?
Please let me know! Thanks a mill!!!
the url header for the form is: edit-education.php?idz='$idz'
i hope this helps out
I am trying to do a query and update that query on a same page by using form but the problem is I have to submit form twice to get it updated. This code is ported from my last mysql project. My last project was search then query then update. This one is query then update. I can't see why form doesn't get variable to it on first click. Still learning PDO. Please point me to a right direction. Thank you.
require_once ('control/control.php');
$db = db_connect ();
$stmt = $db->query("SELECT * FROM offsite_inventory WHERE category != '' ORDER BY FIELD(category,'Sparkling Wine','Rose Wine','Riesling Magnum 1.5L','Riesling Magnum 3L','Austrian Riesling','Austrian Gruner','Trocken','Kabinett','Spatlese','Auslese','Chardonnay USA','Chardonnay France','Chablis','White Wine 1','White Wine 2','Pinot Noir 2','Pinot Noir 1','Cabernet And Bordeau','Red Wine 1','Red Wine 2','Red Wine 3','Red Wine 4','Rhone Valley Red')");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr><td width=\”50\">" . $row['code'] . "</td>
<td width=\"380\">" . $row['name'] . "</td>
<td width=\"50\" align=\"center\">" . $row['instock_resto'] . "</td>
<td width=\"50\" align=\"center\">" . $row['instock_home'] . "</td>
<td width=\"100\"><form style='display:inline!important; width:10px!important;' name='inventory' method='post' action='" . $PHP_SELF . "?id=" . $row['id'] . "&instock_home=" . $row['instock_home'] . "&name=" . $row['name'] . "'>
<table width='1' border='0' align='center' style='margin-right:auto; margin-left:auto;'>
<tr>
<td valign='middle'>
<label><input style='display:inline!important; width:25px!important;' type='number' name='instock_home'/></label></td>
<td>
<input style='display:inline!important; width:100px!important; padding:3px 0px;' type='submit' name='instock_home2' value='update stock' /></td></tr></table>
</form>";
echo "</td></tr>";
}
require_once ('control/control.php');
$conn = db_connect ();
$instock_home = $_POST['instock_home'];
$id = $_GET['id'];
$name = $_GET['name'];
$stmt2= $conn->prepare("UPDATE offsite_inventory SET instock_home = ? WHERE id = ?");
$stmt2->execute(array($instock_home, $id));
echo"</table>";
Hi im running into this error and i just cant seem to see the problem so any ideas, a fresh set of eyes might help.
Full Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='ittititi', price='22', img='img.png'' at line 1
<?php
// Include MySQL class
require_once('../inc/mysql.php');
// Include database connection
require_once('../inc/global.inc.php');
// Include functions
require_once('../inc/functions.inc.php');
// Start the session
session_start();
?>
<?php
// try to create a new record from the submission
$genre = mysql_real_escape_string($_REQUEST['genre']);
$title = mysql_real_escape_string($_REQUEST['title']);
$desc = mysql_real_escape_string($_REQUEST['desc']);
$price = mysql_real_escape_string($_REQUEST['price']);
$img= mysql_real_escape_string($_REQUEST['img']);
if (!empty($genre) && !empty($title) && !empty($desc) && !empty($price) && !empty($img)) {
// here we define the SQL command
$query = "SELECT * FROM books WHERE title='$title'";
// submit the query to the database
$res=mysql_query($query);
// make sure it worked!
if (!$res) {
mysql_error();
exit;
}
// find out how many records we got
$num = mysql_numrows($res);
if ($num>0) {
echo "<h3>That book title is already taken</h3>\n";
exit;
}
// Create the record
$query = "INSERT INTO books SET genre='$genre', title='$title', desc='$desc', price='$price', img='$img'";
$res = mysql_query($query)or die(mysql_error());
if (! $res) {
echo mysql_error();
exit;
} else {
echo "<h3>Book Created</h3>\n";
echo $_SESSION['title']=$title;
}
}
?>
<form name="newbook" method="post">
<table border=0>
<tr>
<td>Genre:</td>
<td><input type=text name='genre'></td>
</tr>
<tr>
<td>Title:</td>
<td><input type=text name='title'></td>
</tr>
<tr>
<td>Description:</td>
<td><input type=text name='desc'></td>
</tr>
<tr>
<td>Price:</td>
<td><input type=number name='price'></td>
</tr>
<tr>
<td>Image:</td>
<td><input type=text name='img'></td>
</tr>
<tr>
<td colspan=2>
<input type=submit value="Create my account">
</td>
</tr>
</table>
</form>
You need to escape reserved words in MySQL like desc with backticks
INSERT INTO books
SET genre = '$genre', title = '$title', `desc` = '$desc'
^----^-----------------here
desc is reserved keyword for mysql
use it like that
`desc`
this must ne your query
$query = "INSERT INTO books SET genre='$genre', title='$title', `desc`='$desc', price='$price', img='$img'";
Don't use desc as a column name; it is a keyword. If you use it as a column name, you have to quote it.
Actually I have a CGI form which consists of textfields and I need a combobox in which I can enter my own data dynamically. May be it seems very silly question but I am new to cgi-perl as well as HTML so no idea what to do. Here is my form:
#!C:\perl\bin\perl.exe
use CGI;
use CGI qw/:standard/;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my $q = new CGI;
use DBI;
use CGI qw(:all);
use strict;
use warnings;
print "Content-Type: text/html\n\n";
print $q->header ( );
if ( $q->param("submit") )
{
process_form ( );
}
else
{
display_form ( );
}
sub process_form
{
if ( validate_form ( ) )
{
display_form ( );
}
}
sub validate_form
{
my $User_Name = $q->param("User_Name");
my $User_Password= $q->param("User_Password");
my $User_Permission = $q->param("User_Permission");
my $User_Department= join(", ",$q->param("User_Department"));
my $error_message = "";
$error_message .= "Please enter your name<br/>" if( !$User_Name );
$error_message .= "Please enter your Password<br/>" if( ! $User_Password );
$error_message .= "Please Select a permission<br/>" if( !$User_Permission );
$error_message .= "Please select atleast 1 department<br/>" if(!$User_Department);
if ( $error_message )
{
display_form (
$error_message,$User_Name,$User_Password,$User_Permission,$User_Department);
return 0;
}
else
{
my $dbh = DBI->connect("dbi:SQLite:DEVICE.db","", "",{RaiseError => 1, AutoCommit =>
1 } );
my $sql = "SELECT COUNT(UserName) FROM UsersList WHERE UserName='$User_Name'";
my $sth = $dbh->prepare($sql) or die("\n\nPREPARE ERROR:\n\n$DBI::errstr");
$sth->execute or die("\n\nQUERY ERROR:\n\n$DBI::errstr");
my ($n) = $dbh->selectrow_array($sth);
$sth->finish();
if ($n > 0) {
print "Record Already Exists";
}
else {
my $sql = "INSERT INTO UsersList (UserName,Password,Permission,Department) VALUES
('$User_Name ',' $User_Password','$User_Permission','$User_Department')";
my $sth = $dbh->prepare($sql);
$sth->execute;
print "Record Added Successfully";
$sth->finish();
$dbh->commit or die $dbh->errstr;
}
$dbh->disconnect;
}
}
sub display_form
{
my $error_message = shift;
my $User_Name = shift;
my $User_Password = shift;
my $User_Permission= shift;
my $User_Department= shift;
my $User_Permission_Add_sel = $User_Permission eq "Add" ? " checked" : "";
my $User_Permission_Edit_sel =$User_Permission eq "Edit" ? " checked" : "";
my $User_Permission_Delete_sel =$User_Permission eq "Delete" ? " checked" : "";
my $User_Permission_View_sel =$User_Permission eq "View" ? " checked" : "";
my $User_Department_html = "";
my $dbh = DBI->connect("dbi:SQLite:DEVICE.db","", "",{RaiseError => 1, AutoCommit =>
1 } );
my $sql = "select DepartmentName from Departments order by DepartmentName";
my $sth = $dbh->prepare($sql);
$sth->execute() ;
while (my $User_Department_option= $sth->fetchrow_array)
{
$User_Department_html.= "<option value=\"$User_Department_option\"";
$User_Department_html.= " selected" if ( $User_Department_option eq
$User_Department );
$User_Department_html.= ">$User_Department_option</option>";
}
$sth->finish();
$dbh->commit or die $dbh->errstr;
print <<END_HTML;
<html>
<head><title>Form Validation</title></head>
<body>
<form action="AddUser.cgi" method="post">
<input type="hidden" name="submit" value="Submit">
<p>$error_message</p>
<TABLE BORDER="1" align="center">
<TR>
<TD>Name</TD>
<TD> <input type="text" name="User_Name" value="$User_Name"></TD>
</TR>
<TR>
<TD>Password</TD>
<TD colspan="2"><input type="password" name="User_Password" value="$User_Password"
size="20" maxlength="15" /></TD>
</TR>
<TR>
<TD>Role</TD>
<TD>"HERE I NEED A COMBOBOX"</TD>
</TR>
<TR>
<TD>Permission</TD>
<TD><input type="radio" name="User_Permission"
value="Add"$User_Permission_Add_sel>Add<input type="radio" name="User_Permission"
value="Edit"$User_Permission_Edit_sel>Edit<input type="radio"
name="User_Permission" value="Delete"$User_Permission_Delete_sel>Delete<input
type="radio" name="User_Permission" value="View"$User_Permission_View_sel>View</TD>
</TR>
<TR>
<TD>Department</TD>
<TD colspan="2"> <select name="User_Department" MULTIPLE
SIZE=4>$User_Department_html</select></TD>
</TR>
</TR>
<TR>
<TD align="center" colspan="2">
<input type="submit" name="submit" value="ADD">
</TD>
</TR>
</TABLE
</form>
</body></html>
END_HTML
}
What you're looking for here isn't done on the Perl side, but on the HTML+Javascript side. As noted by others, HTML does not have a built-in combo box form element. So, you're stuck with Javascript.
Personally, I like using JQuery whenever working with Javascript. It's a Javascript library which makes manipulating web pages elements much easier.
Specific to your question, you'll want to look at http://jqueryui.com/demos/autocomplete/ (there is an actual combobox demo linked on the right, if you really, really need a combobox instead of a Google-style autocomplete text field.
Not related to the combobox, but you might also want to look at Template::Toolkit - a templating system for Perl (and others) that will allow you to take the HTML out of your perl scripts. Believe me, having the HTML embedded in CGI scripts for anything beyond the most basic usages will turn into a nightmare soon enough.
In place of "HERE I NEED A COMBOBOX" you have to write :
<select name='User_Department' id='User_Department'>
$User_Department_html
</select>
However, you retrieve parameters within your sub display_form but you've never passed any.