0

I created a PHP Drop Down which is populated from a MySql Database and works just fine, the problem occurs when I want to post the selected in another script. The question is how to post the data to the other script? This is the source code of the script that implements the drop downs. Please Help!!!!

<?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);
?>
  • PHP's `ext/mysql` (the `mysql_*` family) is [deprecated](http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated). Please use [something else](http://www.php.net/manual/en/mysqlinfo.api.choosing.php) instead. – pilcrow Jul 02 '12 at 18:43

1 Answers1

0

A <select> box is not enough, you need to enclose it in a form

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

then create somescript.php and access your form variables using $_POST

Also use PDO not mysql_ functions as these arent safe

allen213
  • 2,267
  • 2
  • 15
  • 21
  • I tried that but it didn't resolve the issue ... when I call for the variables in somescript.php it says Notice: Undefined index: ProzivodID in C:\xampp\htdocs\EKupuvac\kupi.php on line 24 Notice: Undefined index: KupuvacID in C:\xampp\htdocs\EKupuvac\kupi.php on line 25 – Andrew Albert Petrovsky Jul 02 '12 at 16:39