由于某种原因它不会更新,而是会添加新数据。我是初学者,我很难找到错误。
读取功能非常正常,插入工作也很好。它只是更新无法正常工作或插入而不是更新查询或数据。
<?php include "db.php"; ?>
<?php include "functions.php" ?>
<?php
if(isset($_POST['submit']))
{$username = $_POST['username'];
$password = $_POST['password'];
$id = $_POST['id'];
$querys = "UPDATE users SET ";
$querys .= "username = '$username', ";
$querys .= "password = '$password' ";
$querys .= "WHERE id = $id ";
$result = mysqli_query($connection, $querys);
if(!$result)
{
die('Query FAILED'. mysqli_error($connection));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css
">
</head>
<body>
<div class="container">
<div class="col-xs-6">
<form action="login_create.php" method="post">
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" class="form-control">
</div>
<div class="form-group">
<select name="id" id="">
<?php
showAllData();
?>
</select>
</div>
<input class="btn btn-primary"
type="submit" name="submit" value="Update">
</form>
</div>
</div>
</body>
</html>
感谢您的帮助。
答案 0 :(得分:-1)
您好,这是更新的一个小例子
if(isset($_POST["submit"])) {
$link=Conect();
$id=$_POST["id"];
$value1=$_POST["value1"];
$value2=$_POST["value2"];
$value3=$_POST["value3"];
$query = "UPDATE table_name SET field1='".$value1."',
field2='".$value2."',
"."field3='".$value3."' WHERE id='".$id."'";
$action =mysql_query($query,$link);
$result=mysql_query($query,$link) or die("Error: ".mysql_error());
echo "was update the code: ".$id;
}
祝你好运