chuckf201
Posts: 10
Joined: Sat Apr 08, 2017 11:39 pm

getting assigned value from 'system call' to an HTML button value

Sat Jun 02, 2018 6:59 pm

Trying to assign a variable from PHP 'system' command to a button value based upon a pin value ( 0 or 1).
My code looks like this:
$closepin = system("gpio -g read 27"); [displays a '1' or '0' depending on mag switch open or closed.] it's ok
//************TEST********************
if ($closepin = 1)
{
$closepin= "open";
}
if ($closepin = 0)
{
$closepin= "closed";
}
echo fprintf("A String " , $clospin); [displays nothing]
echo $closepin; [displays '0']
Where is my error? I eventually want to change a button label from 'open' to 'close'

User avatar
bob_binz
Posts: 441
Joined: Thu Feb 02, 2012 7:58 pm
Location: Stockport, UK

Re: getting assigned value from 'system call' to an HTML button value

Sun Jun 03, 2018 7:06 am

Php tests for equality needs doeble equals operator, e.g.

Code: Select all

if ($closepin == 1)
 ...
--
BBz]

User avatar
rpdom
Posts: 14768
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: getting assigned value from 'system call' to an HTML button value

Sun Jun 03, 2018 7:20 am

chuckf201 wrote:
Sat Jun 02, 2018 6:59 pm
echo fprintf("A String " , $clospin); [displays nothing]
Not surprising. There are at least four errors in that statement (assuming they aren't just copy/paste tyops).
echo fprintf(....). What?
echo is used to display stuff. The fprintf after it is pointless.

Code: Select all

echo "My name is rpdom\n";
fprintf is used to write formatted things to a file.

Code: Select all

fprintf($file, "My name is %s\n", "rpdom");
$clospin isn't defined. It's $closepin.
If you intended to use printf instead of fprintf, you haven't put any format command in the string to make it output the value.
The line I'd use would be

Code: Select all

printf("A String %s\n" , $closepin);
The %s will be substituted with the contents of $closepin and the "\n" on the end will force a new line

chuckf201
Posts: 10
Joined: Sat Apr 08, 2017 11:39 pm

Re: getting assigned value from 'system call' to an HTML button value

Sun Jun 03, 2018 4:05 pm

Thanks to you all. BBj] double equal worked.
Also, understanding printf was helpful. thanks.

chuckf201
Posts: 10
Joined: Sat Apr 08, 2017 11:39 pm

Re: getting assigned value from 'system call' to an HTML button value

Sun Jun 03, 2018 4:21 pm

Works great.

Now, can I assign $closepin to a button label in w3-btn ?

umair123
Posts: 1
Joined: Mon Apr 08, 2019 10:48 am
Contact: Website

Re: getting assigned value from 'system call' to an HTML button value

Mon Apr 08, 2019 10:53 am

Because of all of you. BBj] twofold equivalent worked.

Additionally, understanding printf was useful. much obliged.
https://malikexpress.com/Flight/Airblue

Eastern highway
Posts: 1
Joined: Fri Mar 29, 2019 12:19 pm
Contact: Website

Re: getting assigned value from 'system call' to an HTML button value

Sat May 04, 2019 7:35 am

Having the same issue from somedays BB], Trying this out and i guess its kind of working for me.
Now, can is assign button labels in w3-btn programme ? seems its the good way for this to be worked.
https://easternhighway.com

rankray
Posts: 1
Joined: Thu May 30, 2019 6:21 pm
Contact: Website

Re: getting assigned value from 'system call' to an HTML button value

Thu May 30, 2019 6:28 pm

This kinda worked for me. I didnt understand though but right now the problem is solved. Thanks, great tip. Much appreciated.
https://rankray.com

Return to “General discussion”