Answer the question
In order to leave comments, you need to log in
AJAX, PHP, SQL data processing?
There is a site, type of a note. It is necessary that when the button is pressed, another form opens, and the input already contains the value of this note obtained from the database. All for the purpose of further editing.
How I want to implement this:
1) Get the ID of the selected note (succeeded)
2) Pass AJAX (succeeded)
3) Pass PHP (succeeded)
4) Get data in the table by this ID ( fails)
5) Get this data back and script JS to display in Input. (It does not work)
I don’t know how clear I made the question. But if you suddenly need some code, then I'll throw it off.
PHP - code.
<?php
//получаем id выбранной записи. Через AJAX передаем в этот скрипт, нужно по этому id выполнился запрос
$id= $_POST['id'];
require 'configDB.php'; // подключаемся к БД
$sql = 'SELECT * FROM `tasks` WHERE `id`= :id' ; // запрос вроде бы правильный
$query = $pdo->prepare($sql);
while ($row = $query->fetch(PDO::FETCH_OBJ))
{
// тут что-то должно быть
}
?>
function openEdit(id) {
var dd = id;
$.ajax({
url: 'get_id_info.php',
method: 'post,
dataType: 'html',
data: {id:dd},
success: function(data){
//По идее, здесь я должен получить данные от запроса и на их основе что-то делать
}
});
Answer the question
In order to leave comments, you need to log in
On the third attempt, we will be able to finish this extremely complex code
$sql = 'SELECT * FROM `tasks` WHERE `id`= :id' ; // запрос вроде бы правильный
$query = $pdo->prepare($sql);
$query->execute(['id' => $id]); // а выполнить забыли
echo json_encode($query->fetchAll(PDO::FETCH_OBJ)); // ой, а while оказывается не нужно!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question