LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-12-2008, 10:34 AM   #1
starkes
LQ Newbie
 
Registered: May 2006
Posts: 14

Rep: Reputation: 0
new to php, have a noob php question!


Hey there.

I'm trying to make a webpage that, through the use of php, will let me enter some information into forms and pass it on to a bash script.

I have a really simple page working where I can enter information into a form and submit it, and I am able to run a bash script through php. I am also able to print out what was entered in the form, but when I try to run the bash script and give it what was entered in the form, I only get the variable name, not its contents.

the whole thing goes like this

text from form goes to bash script ---> bash script relays this to a file to be checked ---> file contains only the word name.

this is my index.html with the forms
---------------------------
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</body>
</html>

this is my test.php that relays the form's stuff to the bash script
-----------------------------
<html>
<body>
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('test.sh' . " " . '$_POST["name"]');
echo 'You entered ' . $_POST["name"] . "!";
?>
</form>
</body>
</html>


the bash script IS executing and passing the first argument to it into a file I can check. But instead of the file containing what you entered in the form, it only contains "name". What throws me off is that I can print the contents of name in the webpage just fine.

in short:

echo exec('test.sh' . " " . '$_POST["name"]'); ends up sending just "name" to test.sh

echo 'You entered ' . $_POST["name"] . "!"; prints the contents of name.

how is this possible? how do i get the contents of name passed into the bash script?


thanks.
 
Old 09-12-2008, 10:51 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I think the quotes are not correct, try:
PHP Code:
echo exec('test.sh' ' ' $_POST['name']); 
 
Old 09-12-2008, 11:03 AM   #3
starkes
LQ Newbie
 
Registered: May 2006
Posts: 14

Original Poster
Rep: Reputation: 0
damn it! thank you, that was definitely it.
 
Old 09-12-2008, 05:39 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
In php the double quote is a suggestion to the interpreter to expand any variable, whilst the single quote will never expend any variable. Thus $i = 7; echo '$i'."=$i"; will result in $i=7 being displayed. Things get a little more complicated when you have arrays, since (if I recall correctly) the interpreter will expand the first thing that it can hence, "$POST['name']" would be expanded to Array['name'], since $POST is an array. To force the array element to be expanded in double quotes you can include them in braces thus "{$POST['name']}". This means that you exec call could be exec("test.sh {$_POST['name']}");
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
noob php/mysql question babag Programming 2 05-15-2006 08:32 PM
PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work gtrawoger Linux - Software 3 12-21-2005 06:51 AM
noob php question verbatim Programming 5 04-30-2005 06:17 PM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
noob php question centr0 Programming 3 05-12-2003 03:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration