gpt4 book ai didi

php - 使用唯一键更新sql字段

转载 作者:行者123 更新时间:2023-11-29 22:29:39 25 4
gpt4 key购买 nike

我在“名称”字段中使用唯一键,但是当我通过管理员使用编辑文件更新记录时,它会出现重复条目​​错误。我无法删除唯一 key ,这是必需的..

<!--update process-->
<?php
if(isset($_POST['submit']) and !empty($_POST['token'])){
print_r($_POST);
$name = $_POST['name'];
$size = $_POST['size'];
$linkt = $_POST['link'];
$seeds = $_POST['seeds'];
$leechs = $_POST['leechs'];
$active = $_POST['active'];

$query = "UPDATE tplus_torrentlist SET name = '$name', size = '$size', link = '$linkt', seeds = '$seeds', leechs = '$leechs', active = '$active'";

$result = mysqli_query($link, $query) or die(mysqli_error($link));

$error = mysqli_error($link);
if(empty($error)){
$_SESSION['flash'] = '<blockquote style="background: green; color: #fff">One record updated</blockquote>';
header('location:dashbord.php');
}
else{
$_SESSION['flash'] = '<blockquote style="background: green; color: #fff">Sorry cant updated this record</blockquote>';
header('location:dashbord.php');
}
}
?>
<!--fetch values from database according to id-->

<?php
$sql = "SELECT * FROM tplus_torrentlist WHERE id = $id limit 1";
$result = mysqli_query($link ,$sql) or die(mysqli_error($link));
$row = $result->fetch_array();
?>

<div class="container">
<div class="row clearfix">

<div class="col-md-8 col-md-offset-2">
<?php if(!empty($response)){echo $response;} ?>
<h3>Edit this torrent</h3>
<hr/>
<form role="form" class="form" action="edit.php?id=<?php echo $_GET['id']?>" method="POST">

<label>Name</label>
<input type="text" name="name" value="<?php echo $row['name']?>" class="form-control input-sm">

<label>Size</label>
<input type="text" name="size" value="<?php echo $row['size']?>" class="form-control input-sm">

<label>Link</label>
<input type="text" name="link" value="<?php echo $row['link']?>" class="form-control input-sm">

<label>Seeds</label>
<input type="text" name="seeds" value="<?php echo $row['seeds']?>" class="form-control input-sm">

<label>Leechs</label>
<input type="text" name="leechs" value="<?php echo $row['leechs']?>" class="form-control input-sm">

<label>Active</label>
<select name="active" class="form-control input-sm">
<?php if($row['active'] ==0){?>
<option value="0">Active</option>
<option value="1">InActive</option>
<?php }else{ ?>
<option value="1">InActive</option>
<option value="0">Active</option>
<?php } ?>
</select>

<br/>
<input type="hidden" name="token" value="<?php echo rand(100, 100000)?>">
<input type="submit" name="submit" value="update torrent" class="btn btn-info">
</form>
</div>

</div>
</div>

有没有从“名称”字段中删除唯一键的解决方案?

最佳答案

您的更新查询需要更正如下 -

$query = "UPDATE tplus_torrentlist SET name = '$name', size = '$size', link = '$linkt', seeds = '$seeds', leechs = '$leechs', active = '$active' WHERE id = $id limit 1";

关于php - 使用唯一键更新sql字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29920306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com