[英]How do I change state value on MySQL with an a href?
I can't change the state of a value with a href.我无法用 href 更改值的 state。 I have tried in all ways.
我已经尝试了各种方式。 Here is my code
这是我的代码
<a href="giallo.php?id=' . $row['id'] . '">Giallo</a>
giallo.php= giallo.php=
<?php
// Create connection
$conn = new mysqli('localhost','root','','agenda');
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$id = $_GET['id'];
$qry = mysqli_query($db,"select * from note where id='$id'"); // select query
// when click on Update button
if(isset($_POST['update'])) {
$colore=1;
$edit = mysqli_query($db,"update note set colore='$colore' where id='$id'");
if($edit) {
mysqli_close($db); // Close connection
header("location:udienze.php"); // redirects to all records page
exit;
} else {
echo mysqli_error();
}
}
if (mysqli_query($conn, $sql)) {
echo "<script>
alert('Nota inserita correttamente');
window.location.href='add-udienze.php';
</script>";
} else {
echo "<script>
alert('Errore');
window.location.href='add-udienze.php';
</script>";
}
mysqli_close($conn);
?>
What is wrong with my code?我的代码有什么问题? There are probably cleaner ways to do it.
可能有更清洁的方法来做到这一点。 I have tried all ways that I know.
我已经尝试了所有我知道的方法。
I think the problem is that you are calling the giallo.php script with multiple kind of params (POST and GET).我认为问题在于您使用多种参数(POST 和 GET)调用 giallo.php 脚本。
So when you click on the link, the "href" attribute redirects to giallo.php, but nothing happen because it miss the $_POST['update'] action.因此,当您单击链接时,“href”属性会重定向到 giallo.php,但没有任何反应,因为它错过了 $_POST['update'] 操作。
Probably the solution fit your case can be edit the href attribute, adding a GET parameter for "update", like:可能适合您情况的解决方案可以编辑 href 属性,为“更新”添加 GET 参数,例如:
<a href="giallo.php?update=1&id=' . $row['id'] . '">Giallo</a>
And then edit the giallo.php file and consider the new $_GET["update"] and not the POST one.然后编辑 giallo.php 文件并考虑新的 $_GET["update"] 而不是 POST 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.