gpt4 book ai didi

php - php 中的重复值 ' found in column ' id'

转载 作者:行者123 更新时间:2023-11-28 23:09:26 25 4
gpt4 key购买 nike

我的数据库名称中有一个表是 mdl_assigncourses..所以我有列作为 id(主键)、groupid、courseid、status..

所以当我要将类(class)添加到组中时,如果它已经存在于表中,我想显示错误消息,如“这门类(class)已经上过”..并且它也没有存储在表中..

现在对我来说它显示了这个错误..您是否记得在调用 get_records 时将第一列设为唯一?在“id”列中发现重复值“63”。但此记录仍存储在数据库中...

这是我的插入代码:

if(isset($_POST['assigncourse'])) { 


$courseid = $_POST['courseid'];

$courseid = required_param('courseid', PARAM_TEXT);
$groupid = required_param('groupid', PARAM_TEXT);

$insert_record = new stdClass();
$insert_record->courseid = $courseid;
$insert_record->groupid = $_SESSION['groupid'];
$insert_record->assigned_date = date('Y-m-d H:i:s');
if($result = $DB->insert_record('assigncourses', $insert_record) )
{
$_SESSION['successMessage'] = "record created successfully";
header('Location: ' . $_SERVER['HTTP_REFERER']);
}

//$stmt->bindParam("groupid", $_SESSION['groupid'],PDO::PARAM_STR) ;
}

谁能帮帮我..怎么做..

提前致谢..

最佳答案

    if(isset($_POST['assigncourse'])) { 

$groupid=$_SESSION['groupid']
$courseid = $_POST['courseid'];

$courseid = required_param('courseid', PARAM_TEXT);
$groupid = required_param('groupid', PARAM_TEXT);

//$con is your db connection
$sql=mysqli_query($con," SELECT * FROM mdl_assigncourses WHERE groupid='$groupid' AND courseid='$courseid' ");

$row=mysqli_num_rows($sql);

if($row>0){

$insert_record = new stdClass();
$insert_record->courseid = $courseid;
$insert_record->groupid = $_SESSION['groupid'];
$insert_record->assigned_date = date('Y-m-d H:i:s');
if($result = $DB->insert_record('assigncourses', $insert_record) )
{
$_SESSION['successMessage'] = "record created successfully";
header('Location: ' . $_SERVER['HTTP_REFERER']);
}

//$stmt->bindParam("groupid", $_SESSION['groupid'],PDO::PARAM_STR) ;
}

}else{
echo "<script>alert('groupid and courseid should be unique');window.location.href='form.php';</script>";

}

关于php - php 中的重复值 ' found in column ' id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46358705/

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