# How to insert console.log(res) data to database using php mysqli

**URL:** <https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547>\
**Category:** Web\
**Created:** [July 8, 2020, 12:49pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547 "2020-07-08T12:49:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 8, 2020, 12:49pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/1 "2020-07-08T12:49:18Z")

</div>

**Description**  
i am new to node js so i am not able to insert data which is in console.log(res) of attendees details ,i need to use php mysqli to insert it into database.but index.js is in node js.thanks in advance

---

<div class="post-metadata">

**Author:** ![daniel2](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/daniel2/32/8619_2.png) [@daniel2](https://devforum.zoom.us/u/daniel2)\
**Post date:** [July 8, 2020, 4:23pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/2 "2020-07-08T16:23:10Z")

</div>

I’d say make a POST request with the data to your own PHP file, and in that file do the database logic.

Do not put any code dealing with databases in the web browser, in this case the Node.js client code. That will expose any credentials you may use to connect to the database.

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 8, 2020, 5:14pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/3 "2020-07-08T17:14:36Z")

</div>

I know php but attendee list result is in js file how to retrive it to php file to database?

---

<div class="post-metadata">

**Author:** ![daniel2](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/daniel2/32/8619_2.png) [@daniel2](https://devforum.zoom.us/u/daniel2)\
**Post date:** [July 8, 2020, 5:27pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/4 "2020-07-08T17:27:57Z")

</div>

You can use `fetch()` for making HTTP requests. [MDN Documentation here](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch).

This code should work. Just replace the URL to the URL of your own PHP file! This example assumes you want to send the data as JSON.

```auto
/* ... */

ZoomMtg.getAttendeeslist({
  success (res) {
    if (res) {
      if (res.errorCode > 0 || res.errorMessage !== null || res.status === false) {
        return void console.error(res)
      }

      if (Array.isArray(res.result.attendeesList)) {
        console.log('Retrieved attendees list')

        const myUrl = 'https://myowndomain.com/upload_attendees_list.php'

        fetch(myUrl, {
          method: 'post',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify(res.result.attendeesList)
        })
      } else {
        console.warn('Attendees list result was not an array!', res.result)
      }
    } else {
      console.warn('No result object in getAttendeeslist success handler')
    }
  },
  error (err) {
    console.error('Could not get attendees list!', err)
  }
})

/* ... */

```

---

<div class="post-metadata">

**Author:** ![daniel2](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/daniel2/32/8619_2.png) [@daniel2](https://devforum.zoom.us/u/daniel2)\
**Post date:** [July 9, 2020, 11:41am UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/6 "2020-07-09T11:41:52Z")

</div>

Okay, so you’re accepting FormData in your PHP file, with the `res` key. Therefore we need to alter the JavaScript to something like this instead:

```auto
/* ... */
const myUrl = '...';
const form = new FormData()
form.append('res', res.result.attendeesList)

fetch(myUrl, {
  method: 'post',
  body: form
}).then(() => {
  console.log('The data was uploaded!')
}).catch(err => {
  console.error('HTTP request failed', err)
})
/* ... */

```

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 9, 2020, 11:46am UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/7 "2020-07-09T11:46:39Z")

</div>

no…in upload\_attendees\_list.php how to get json.stringify(res) because its showing null…i dont want to use form data…i want to get json data to upload\_attendees\_list.php and do database connection and store the json data…

---

<div class="post-metadata">

**Author:** ![daniel2](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/daniel2/32/8619_2.png) [@daniel2](https://devforum.zoom.us/u/daniel2)\
**Post date:** [July 9, 2020, 12:14pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/8 "2020-07-09T12:14:48Z")

</div>

In `upload_attendees_list.php`:

```php
// Get input data as JSON
$data = json_decode(file_get_contents('php://input'), true);

echo $data;

/* Now use the $data for inserting into db */

```

In the JavaScript file, use the previous code sample, the one with `’Content-Type’: ’application/json’`.

Also, please sanitize the php input before using it in the SQL query!

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 9, 2020, 12:25pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/9 "2020-07-09T12:25:02Z")

</div>

thank you for your reply.its working after using json encode

$data = json\_decode(file\_get\_contents(‘php://input’), true);  
$newdata=json\_encode($data);  
echo $newdata;

---

<div class="post-metadata">

**Author:** ![daniel2](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/daniel2/32/8619_2.png) [@daniel2](https://devforum.zoom.us/u/daniel2)\
**Post date:** [July 9, 2020, 1:10pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/10 "2020-07-09T13:10:30Z")

</div>

Yes, the `ZoomMtg.getAttendeeslist()` function returns an array in `res.result.attendeesList`. Therefore, an array is sent as JSON.

In your PHP file, you need to decode the JSON, which the code I sent does.

This gives you a PHP array of all the attendees. Then you have to loop through that array to insert each attendee one by one, if that’s what you want to do.

So your PHP file should probably look something like this:

```php
<?php
$data = file_get_contents('php://input');
$attendeesList = json_decode($data, true);

print_r($attendeesList);

require("db/connect.php");

if (is_array($attendeesList)) {
  $DataArr = array();
  foreach ($attendeesList as $key => $attendee) {
    $username = mysql_real_escape_string($attendee["userName"]);
    
    $DataArr[] = "('$username')";
  }
  
  $sql = "INSERT INTO attendees (username) values ";
  $sql .= implode(",", $DataArr);
  
  echo $sql;
  
  $res = mysql_query($conn, $sql);
  
  if ($res) {
    echo "inserted";
  } else {
    echo "not";
  }
}
?>

```

Links:

- [https://www.codexworld.com/post-receive-json-data-using-php-curl/](https://www.codexworld.com/post-receive-json-data-using-php-curl/)
- [https://jonsuh.com/blog/convert-loop-through-json-php-javascript-arrays-objects/](https://jonsuh.com/blog/convert-loop-through-json-php-javascript-arrays-objects/)
- [https://www.phpflow.com/php/insert-php-array-into-mysql-table/](https://www.phpflow.com/php/insert-php-array-into-mysql-table/)

This starts to look like StackOverflow lol.

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 9, 2020, 1:33pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/11 "2020-07-09T13:33:25Z")

</div>

Thank you …I will use this code and check it out…

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 10, 2020, 8:28am UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/12 "2020-07-10T08:28:33Z")

</div>

okay thank you i have changed code but working fine…

websdk unable to start video.Your camera has been occupied by other apps, please release the privilege and try again.how to start when i click on video…

attendee list not visible after admitting attendee and not storing data ,again i have to refresh page to insert,how to solve this problem

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 10, 2020, 2:22pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/13 "2020-07-10T14:22:06Z")

</div>

After participant admit by host…it’s not storing attendence to database once I refresh page it wil store to database …I don’t want to refresh…once admit by host to participate store name to database without refresh the page

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 10, 2020, 2:35pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/14 "2020-07-10T14:35:38Z")

</div>

Hi…  
Atendee’s name not storing to dataabse once host admit to participate,through Gmail I invite each participate and url is [https://us04web.zoom.us/j/76860445789?pwd=MUtBdGs5ZVFueG9VcTkxanRjYUplQT09](https://us04web.zoom.us/j/76860445789?pwd=MUtBdGs5ZVFueG9VcTkxanRjYUplQT09)  
Automatically it won’t store name to database again I have to refresh but it’s not possible for all time…solution please

---

<div class="post-metadata">

**Author:** ![daniel2](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/daniel2/32/8619_2.png) [@daniel2](https://devforum.zoom.us/u/daniel2)\
**Post date:** [July 10, 2020, 6:18pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/15 "2020-07-10T18:18:55Z")

</div>

I think it all depends on where you call `getAttendeeslist()` and the `fetch()` request. Perhaps it would be easier if you could link to a GitHub page or something, so I can take a look at your code.

Can you show what your JavaScript code looks like now?

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 11, 2020, 3:29am UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/16 "2020-07-11T03:29:02Z")

</div>

exactly same code I have used whatever u sent…but once user click on link it goes to either lounch website in browse or download zoom…once user enter his name and password it will wait for host to admin it…but the attendee name automatically not inserting it to database…

---

<div class="post-metadata">

**Author:** ![daniel2](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/daniel2/32/8619_2.png) [@daniel2](https://devforum.zoom.us/u/daniel2)\
**Post date:** [July 11, 2020, 8:44am UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/19 "2020-07-11T08:44:14Z")

</div>

Have a look over here: [getAttendeeslist() doesn't show attendees in console log only showing host name but not other attendees](https://devforum.zoom.us/t/getattendeeslist-doesnt-show-attendees-in-console-log-only-showing-host-name-but-not-other-attendees/23843/2)

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [July 14, 2020, 10:06pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/20 "2020-07-14T22:06:10Z")

</div>

Thanks for contributing to the Zoom Developer Community @daniel2! 🙂

@yash.sakali, let me know if you have any additional questions.

-Tommy

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 15, 2020, 5:35am UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/21 "2020-07-15T05:35:19Z")

</div>

I can view participate after joining meeting but how do I insert participate to my database…can you help me to solve this issue?all user not joining from websdk so I don’t want to use getattendeeslist()…any other method tthanks in advance

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [July 16, 2020, 7:23pm UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/22 "2020-07-16T19:23:36Z")

</div>

Hey @yash.sakali,

Here is your answer:

> [@How do i get participant list after creating meeting](https://devforum.zoom.us/t/how-do-i-get-participant-list-after-creating-meeting/23417/12):
>
> Hey @yash.sakali, You can use the Participant Joined Webhook: Or one of our Participant APIs: Thanks, Tommy

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![yash.sakali](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@yash.sakali](https://devforum.zoom.us/u/yash.sakali)\
**Post date:** [July 17, 2020, 2:58am UTC](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547/23 "2020-07-17T02:58:20Z")

</div>

I am not getting how to use participate webhook…can you help me to get it…I need to insert participate to my database…thanks in advance

[Next page](https://devforum.zoom.us/t/how-to-insert-console-log-res-data-to-database-using-php-mysqli/23547.md?page=2)
