0

我创建了一个从 MySql 数据库填充的 PHP Drop Down 并且工作得很好,当我想在另一个脚本中发布所选内容时会出现问题。问题是如何将数据发布到其他脚本?这是实现下拉菜单的脚本的源代码。请帮忙!!!!

<?php
$conn = mysql_connect("localhost", "admin", "admin");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}

if (!mysql_select_db("ekupuvac")) {
    echo "Unable to select EKupuvac: " . mysql_error();
    exit;
}

$query = "SELECT ImeK, KupuvacID FROM kupuvac ORDER BY Saldo DESC";
$result = mysql_query($query) or die(mysql_error());

if (!$result) {
    echo "Could not successfully run query ($query) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so I am exiting";
    exit;
}

$dropdown = "<select name='ImeK'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown.= "\r\n<option value='{$row['KupuvacID']}'>{$row['ImeK']}</option>";
}
$dropdown .= "\r\n</select>";

echo"Izberi Kupuvac:";
echo $dropdown;

// Second Combo

$conn = mysql_connect("localhost", "admin", "admin");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}

if (!mysql_select_db("ekupuvac")) {
    echo "Unable to select EKupuvac: " . mysql_error();
    exit;
}

$query2 = "SELECT ImeP, ProzivodID FROM proizvod ORDER BY ImeP";
$result2 = mysql_query($query2) or die(mysql_error());

if (!$result2) {
    echo "Could not successfully run query ($query2) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result2) == 0) {
    echo "No rows found, nothing to print so I am exiting";
    exit;
}

$dropdown2 = "<select name='ImeP'>";
while($row = mysql_fetch_assoc($result2)) {
$dropdown2.= "\r\n<option value='{$row['ProzivodID']}'>{$row['ImeP']}</option>";
}
$dropdown2.= "\r\n</select>";

echo"<br> Izberi Proizvod:";
echo $dropdown2;
echo"<br>";

mysql_free_result($result);
?>
4

1 回答 1

0

一个<select>盒子是不够的,你需要把它附在一个表格里

?>
<form method="post" action="somescript.php">
<?
//your controls go here
?>
</form>

然后创建 somescript.php 并使用访问您的表单变量$_POST

也使用PDO而不是 mysql_ 函数,因为这些不是安全的

于 2012-07-02T15:54:18.590 回答