<form action="">
<input type="text" placeholder="Text" class="input_to_text" name="text" id="text"><br>
<label class="switch">
<input type="checkbox" name="category" id="category">
<span class="slider round"></span>
</label>
<div>
<input type="hidden" name="id" id="user_id" />
<button type="button" name="action" id="action" class="publish"></button>
</div>
</form>
while ($row = mysqli_fetch_array($result)) {
$output .= '
<div class="getpost_name">
<p>' . $row["text"] . '</p>
</div>
<div>
<button type="button" name="update" class="update" id="' . $row["id"] . '"></button>
</div>
';
}
if ($_POST["action"] == "Edit") {
$text = mysqli_real_escape_string($connect, $_POST["text"]);
$category = mysqli_real_escape_string($connect, $_POST["category"]);
$procedure = "
CREATE PROCEDURE updateProject(IN user_id int(11), text varchar(250), category varchar(250))
BEGIN
UPDATE projects SET text = text, category = category
WHERE id = user_id;
END;
";
if (mysqli_query($connect, "DROP PROCEDURE IF EXISTS updateProject")) {
if (mysqli_query($connect, $procedure)) {
$query = "CALL updateProject('" . $_POST["id"] . "', '" . $text . "', '" . $category . "')";
mysqli_query($connect, $query);
echo 'Data Updated';
}
}
}
.update
$(document).ready(function() {
fetchUser();
function fetchUser() {
var action = "select";
$.ajax({
url: "select.php",
method: "POST",
data: {
action: action
},
success: function(data) {
$('#category ').val('');
$('#text').val('');
$('#action').text("Add");
$('#result').html(data);
}
});
}
$(document).on('click', '.update', function() {
var id = $(this).attr("id");
$('input[name="top"]').prop('checked', $('#top').val() !== 'notop');
$.ajax({
url: "fetch.php",
method: "POST",
data: {
id: id
},
dataType: "json",
success: function(data) {
$('#action').text("Edit");
$('#user_id').val(id);
$('#category ').val(data.category );
$('#text').val(data.text);
}
})
});
<div class="col-xl-3">
<h5><?php echo $post['title'] ?></h5>
<p><?php echo $post['description'] ?></p>
</div>
182: $post = mysqli_fetch_assoc($result);