Skip to content
Advertisement

Sending variables to a php script for database from java script

First, I have looked at just about every other question here on this subject but I can’t find anything like I need. I’m trying to send the userId for one signal to a PHP script to put it in a database. I have tried many different versions of this.

Here is the script that does send to the PHP script and put’s it in the database but the userId is NULL.

JavaScript

The part to look at is this:

JavaScript

You will notice that I have a var theuserid = userId in there. When I replace useragentid with theuserid in that one line, it don’t send anything over, it’s like it ignores the entire statement. But when I use useragentid it does send to the PHP script but it’s NULL. Why would it work with useragentid but not with theuserid? Is it because one is global and the other is not? Would that cause it to completely ignore the statement when using theuserid because it’s not global?

I’m hoping someone can help with this without the entire code because I’m thinking it’s a simple java script error that I’m causing so I’m thinking that the entire code is really not relevent.

Advertisement

Answer

SOLUTION:

JavaScript

This allows me to get the userId again in a function and then send it to the PHP script which captures it successfully.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement