2012-12-24 64 views
0

如何從選擇選項更新數據庫。從鏈接中選擇選項更新數據庫

如果選擇了測試,則從db行更新用戶標識。

<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"; 
} 
} 
?> 
+0

什麼似乎是問題? – samayo

+1

'UPDATE users'而不是'UPDATE * from'' –

+0

不更新db行 –

回答

1

Here學習MySQL基礎知識。

而變化:

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

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

它不更新數據庫行,表單動作鏈接是用戶標識exp:action =「action.php?id =」?php echo $ dn2 ['userid']?>「 –

0

我認爲你是在談論檢索主鍵id你從action屬性通過get方法發送。將您的查詢更新到

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