views:

287

answers:

2

I have a dropdown menu that is filled by a mysql database. I need to select one and have it send the information for use on the next page after clicking submit. It does populate the drop down menu like it is supposed to it just does not seem to catch the data on the next page. Here is what I have:

removeMain.php

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<form action="remove.php" method="post">
<?php
    $link = mysql_connect('********', '********', '*********');
    if (!$link){
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("********", $link);
    $res = mysql_query("SELECT * FROM cardLists order by cardID") or die(mysql_error()); 
    echo "<select name = CardID>"; 
    while($row=mysql_fetch_assoc($res)) { 
        echo "<option value=$row[ID]>$row[cardID]</a></option>"; 
    } 
    echo "</select>";
?>
Amount to Remove: <input type="text" name="Remove" />
<input type="submit" />
</form>
<body>
</body>
</html>

remove.php

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
$link = mysql_connect('*********', '*********', '*********');
    if (!$link){
        die('Could not connect: ' . mysql_error());
     }

    mysql_select_db("***********y", $link);

 $query = sprintf("UPDATE cardLists SET AmountLeft = AmountLeft - %s WHERE cardID =  '%s'", mysql_real_escape_string($_POST["Remove"]), mysql_real_escape_string($_POST["CardID"]));
 mysql_query($query);
 mysql_close($link);
?>
<br />
<a href="removeMain.php"> <input type="submit" name="return" id="return" value="Update More" /></a>
<a href="index.php"> <input type="submit" name="main" id="main" value="Return To Main" /></a>
</body>
</html>
+1  A: 
while($row=mysql_fetch_assoc($res)) { 
        echo "<option value=$row[ID]>$row[cardID]</a></option>"; 
    } 

echo "<option value=$row[ID]>$row[cardID]</a></option>"; should be
echo "<option value=$row[ID]>$row[cardID]</option>";

dont know if that solves your problem, but it was the first thing i noticed

Grumpy
I took it out, but it did not do anything. Thanks for the catch though it did need to go
shinjuo
+1  A: 
echo "<select name = CardID>";

should be:

echo "<select name = \"CardID\">";
tylerpenney
This still did not work. I changed it to that and it still does not subtract any value from the mysql database.
shinjuo
also you need to change echo <option value=$row[ID]> to <option value=\"$row[ID]\">
tylerpenney