I’m trying to make a note change editor in php and MySQL. But I ran into a problem. There are a lot of notes and to get the right one, I decided to stuff the ID, date, text and title into the properties of the button, but I don’t know how to get the data of a specific note so that.
$sql = "SELECT * FROM notes WHERE id_user = ".$_SESSION['id_user']."";
if($result = mysqli_query($mySql, $sql)){
$results='';
foreach($result as $row) {
$results.='<section class="notes-section section" id="notesCard">
<div id= "noteContent" class="note-content">
<div class="note-h2"><h2 id="headingH2">'.$row['heading'].'</h2></div>
<div class="note-text"><p id="textArea">'.$row['text_content'].'</p></div>
<div class="note-panel">
<label id="dateNotes" for="">'.$row['date'].'</label>
<form action="editNote.php" name="" method="post">
<button name="editNotes" id="edit" class="insert-btn btn" value="'.$row['id_notes'].'">Изменить</button>
<button name="deleteNotes" class="delete-btn btn" value="'.$row['id_notes'].'">Удалить</button>
</form>
</div>
</div>
</section>';
}
echo $results;
} else {
echo "Что-то пошло не так...";
}
if (isset($_POST['deleteNotes']) and is_numeric($_POST['deleteNotes'])) {
$delete = $_POST['deleteNotes'];
if ($mySql -> query("DELETE FROM `notes` WHERE `id_notes` = '$delete'")) {
echo '<script>window.location = "./notes.php"</script>';
}
}
I tried to do everything through js, but I don’t have enough knowledge for this
Sorry for the bad English, Google Translate translated everything