0

I am having a lot of trouble retreiving a Javascript Post in a php file.

I have a function that is getting some values from the DOM and they are stored in variables. See next code.

     const elements = textList.childNodes
     Array.from(elements).forEach(function (element) {
       const item = element.attributes
       let itemClass = element.className
       let itemId = element.dataset.id
       let itemStyle = element.style.height
   
       const data = { name: itemClass, id: itemId, height: itemStyle }
       console.log(data)
       console.log(JSON.stringify(data))
       fetch('http://localhost/fumiko/admin/create-product.php', {
         method: 'POST',
         headers: {
           'Content-Type': 'application/json',
         },
         body: JSON.stringify(data),
       })
         .then((data) => {
           console.log('Success:', data)
         })
         .catch((error) => {
           console.log('Error:', error)
         })
     })
   }

In the console I get a succes message:

Success: Response { type: "basic", url: "http://localhost/fumiko/admin/create-product.php", redirected: false, status: 200, ok: true, statusText: "OK", headers: Headers, body: ReadableStream, bodyUsed: false

But then in the php file.. How do I get the values send from the POST request so that I can store them in phpmyadmin database.

I made the database connection, that is working, but then ... I tried several things, also several ways of sending the data. but this is giving a success messages so I figure I am on the right way. Any tips, advice? MORE then welcome!

Alex K.
  • 171,639
  • 30
  • 264
  • 288
Oghi
  • 11
  • 1
  • 1
    Terminology note: PhpMyAdmin is just a web based administration tool for managing MySQL databases. (It is one of many such administration clients). Your code connects directly to the MySQL database server and doesn't have anything to do with PhpMyAdmin. There is no such thing as a "phpmyadmin database" – ADyson Jun 22 '21 at 12:28
  • Not a [dup](https://stackoverflow.com/q/66805555/1169519), but the answers are answering the question. – Teemu Jun 22 '21 at 12:30
  • I am reading all the answers, but still it seems not possible to get the data visible on my php file so I can send it to my database. I just can not seem to find the logic behind the code. In the console I can see the 'data' but the data on the page 'http://localhost/fumiko/admin/create-product.php' I can not make it visible – Oghi Jun 22 '21 at 16:21

0 Answers0