O
O
odkord2019-11-29 14:08:33
PHP
odkord, 2019-11-29 14:08:33

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))
  {
      // тут что-то должно быть
  }


?>


js code.
function openEdit(id) {
 var dd = id;

 $.ajax({
  url: 'get_id_info.php',
  method: 'post,
  dataType: 'html',
  data: {id:dd},
  success: function(data){
  //По идее, здесь я должен получить данные от запроса и на их основе что-то делать
  }
});


5de0fbefbefda191314477.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2019-11-29
@odkord

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 оказывается не нужно!

R
Rsa97, 2019-11-29
@Rsa97

Forgot to complete the request.

$query = $pdo->prepare($sql);
$query->execute(['id' => $id]);
while ($row = $query->fetch(PDO::FETCH_OBJ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question