2010-03-23 60 views
0

我有一个由mysql数据库填充的下拉菜单。我需要选择一个,并在点击提交之后发送信息以供下一页使用。它确实填充下拉菜单,就像它应该看起来似乎无法捕获下一页上的数据。以下是我有:我有一个需要发送信息的PHP表单下拉菜单

removeMain.php

<html xmlns="http://www.w3.org/1999/xhtml"> 
<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"> 
<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> 
+0

此外,它用来工作时,这只是一个用户输入文本框,但如果他们可以选择自己用的下拉菜单 – shinjuo 2010-03-23 20:00:23

回答

1
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>"; 

不知道是否能解决你的问题,但它是我注意到

的第一件事
+0

我把它入门很容易,但它没有做任何事情。感谢您的接触,但它确实需要去 – shinjuo 2010-03-23 20:19:39

1
echo "<select name = CardID>"; 

应该是:

echo "<select name = \"CardID\">"; 
+0

这仍然没有奏效。我改变它,它仍然不会从MySQL数据库中减去任何值。 – shinjuo 2010-03-23 20:30:13

+0

您还需要将echo