从链接中选择选项更新数据库

时间:2012-12-24 04:58:03

标签: php database select hyperlink option

如何从select选项更新数据库。

如果选择test,则从db row更新用户id。

<form action="action.php?id=<?php echo $dnn['id'] ?>" method="post">
<select name="op">
<option value="test">test</option>
<option value="test2">test2</option>
</select>
<input name="submit" type="submit" value="submit" />
</form>
<?php
if (isset($_POST['submit']))
{
if ($_POST['op'] == "test") 
{ 
$sql = "UPDATE * from users SET increment = increment + 1 WHERE id = '".$id."'";
mysql_query($sql); 
}
else 
{ 
echo "test2 is selected can't update the db"; 
}
}
?>

2 个答案:

答案 0 :(得分:1)

Here了解MySQL基础知识。

并改变:

$sql = "UPDATE * from users SET increment = increment + 1 WHERE id = '".$id."'";

$sql = "UPDATE users SET increment = increment + 1 WHERE id = '".$id."'";

答案 1 :(得分:0)

我认为您正在讨论通过get方法检索您从action属性发送的主键id。将您的查询更新为

$sql = "UPDATE users SET increment = increment + 1 WHERE id = '".$_REQUEST['id']."'";