When I change note, it let me change the name without saying
" you have the same lessons on the lessons list"
$stm = $db->prepare("SELECT * FROM subjects WHERE subject=:sb");
full code
<?php include_once 'header.php'; ?>
<?php include_once 'sidebar.php'; ?>
<?php include_once 'navtop.php'; ?>
<?php include_once 'class.token.php'; ?>
<?php
@$id = isset($_GET['id']) && is_numeric($_GET['id']) ? (int)$_GET['id'] : 1;
if ($id) {
$stm = $db->prepare("SELECT * FROM subjects WHERE id=:id");
$stm->bindParam(":id", $id, PDO::PARAM_STR);
$stm->execute();
$row = $stm->fetch(PDO::FETCH_ASSOC);
}
?>
<div class="container-fluid">
<div class="card shadow mb-4 text-right">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-gray-800">add sebject</h6>
</div>
<div class="card-body">
<?php
if (isset($_POST['sub2'])) {
if(Token::check($_POST['token']) AND !empty($_POST['token'])){
$sb=@output($_POST['sb']);
$note=@output($_POST['note']);
if(!empty($sb)){
$stm = $db->prepare("SELECT * FROM subjects WHERE subject=:sb");
$stm->bindParam(":sb", $sb, PDO::PARAM_STR);
$stm->execute();
$rowCount = $stm->rowCount();
if($rowCount == 0){
$stm = $db->prepare("UPDATE subjects SET subject=:sb,description=:note WHERE id=:id");
$stm->bindParam(":sb", $sb, PDO::PARAM_STR);
$stm->bindParam(":note", $note, PDO::PARAM_STR);
$stm->bindParam(":id", $id, PDO::PARAM_STR);
$stm->execute();
echo "added";
$db = null;
direct("./subject_list.php");
}else {
echo "you have the same lessons on the lessons list";
}
}else {
echo "empty";
}
}else {
echo "try again";
}
}
?>
<div class="container">
<form method="post" action="">
<input type="hidden" name="dat" min="1" step="1" class="form-control"id="start" placeholder="date">
<div class="form-group">
<label for="leavetype">lesson code</label>
<input id="leavetype" type="text" name="cod" value="<?php echo $row['subject_code']; ?>" class="validate form-control" readonly>
</div>
<div class="form-group">
<label for="leavetype">lesson</label>
<input id="leavetype" type="text" name="sb" value="<?php echo $row['subject']; ?>" class="validate form-control">
</div>
<div class="form-group">
<label for="deptshortname">note</label>
<textarea id="textarea1" name="note" class="materialize-textarea form-control" length="500" ><?php echo $row['description']; ?></textarea>
</div>
<input type="hidden" name="token" value="<?php echo Token::create(); ?>">
<p align="center"><button type="submit" name="sub2" class="btn btn-primary" id="butsave">edite</button></p>
</form>
</div>
</div>
</div>
<!-- /.container-fluid -->
<script type="text/javascript">
$('#start').daterangepicker({
singleDatePicker: true,
locale: { format: "YYYY-MM-DD" }
//startDate: moment().subtract(6, 'days')
});
</script>
</div>
<?php include_once 'footer.php'; ?>