简体   繁体   中英

select option update db from linking

How to update the database from select option.

if test is selected update the users id from db row.

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

Learn MySQL Basics from Here .

And Change:

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

to

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

I think you are talking about retrieving primary key id which you are sending from action attribute via get method. Update your query to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM