Skip to content
Advertisement

Why Did The Strings Fail To Transfer From Javascript To Php? [closed]

Ok, so I am trying to send data to php from javascript and I’ve been doing it just fine with ints. However, I can’t seem to do it with strings.

On the below code, the name, email, company, phone, city, state and country are all string fields. Everything else is an int. The ints are transfering just fine, and I’ve done an alert on the variables and I know that they are populated with the right data.

(javascript)

Full

JavaScript

TLDR Snippet that contains just the problem

JavaScript

So I send the stuff off to the php document to process it, but the data is never arriving to the string variables. The int variables process just fine though.

(php) Contains just the problem

JavaScript

The server said that the variables that are strings are undefined.

Here is what the server said:

2021/03/02 16:00:32 [error] 54508#54508: *81719 FastCGI sent in stderr: “PHP message: PHP Notice: Undefined property: stdClass::$name in /www/dmecompany_192/public/Submissions/submitjson.php on line 9PHP message: PHP Notice: Undefined property: stdClass::$email in /www/dmecompany_192/public/Submissions/submitjson.php on line 9PHP message: PHP Notice: Undefined property: stdClass::$company in /www/dmecompany_192/public/Submissions/submitjson.php on line 9PHP message: PHP Notice: Undefined property: stdClass::$phone in /www/dmecompany_192/public/Submissions/submitjson.php on line 9PHP message: PHP Notice: Undefined property: stdClass::$city in /www/dmecompany_192/public/Submissions/submitjson.php on line 9PHP message: PHP Notice: Undefined property: stdClass::$state in /www/dmecompany_192/public/Submissions/submitjson.php on line 9PHP message: PHP Notice: Undefined property: stdClass::$country in /www/dmecompany_192/public/Submissions/submitjson.php on line 9PHP message: PHP Warning: fwrite() expects parameter 2 to be string, object given in /www/dmecompany_192/public/Submissions/submitjson.php on line 10” while reading response header from upstream, client: 98.243.211.186, server: staging-dmecompany.kinsta.cloud, request: “POST /Submissions/submitjson.php HTTP/1.0”, upstream: “fastcgi://unix:/var/run/php7.3-fpm-dmecompany.sock:”, host: “staging-dmecompany.kinsta.cloud”, referrer: “https://staging-dmecompany.kinsta.cloud/Submissions/AccualignROICalc3.php”

Why are the strings failing to process, while the integers are processed without an issue?

Advertisement

Answer

Your javascript object contains capitalized properties, while in your PHP code you are expecting lowercased properties.

Edit your JS code to

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