Home > Archive > PHP Programming > January 2005 > Simple PHP problem - passing arguments to another script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Simple PHP problem - passing arguments to another script
|
|
| Robert Rozman 2005-01-27, 8:56 pm |
| Hi,
I'm total php newbie and probably have trivial problem.
I have following two scripts. First creates web form and should run second
script with two arguments. But those two arguments don't get to second
script, cause this line
print "Please enter both phone number
and name!";
is always executed and incoming arguments are empty.
What is wrong ?
Thanks in advance,
regards,
Rob.
== cid-form.php ==
<html>
<head>
<title>Asterisk Caller ID form</title>
</head>
<body>
<h1>Asterisk phone book</h1>
<form name="EntryForm" action="cid-store.php" method=POST>
<table cellpadding=2>
<tr>
<td>Phone number:</td>
<td><input name="PhoneNumber" size=30></td>
</tr>
<tr>
<td>Name:</td>
<td><input name="PhoneName" size=30></td>
</tr>
<tr>
<td></td>
<td><div align=right>
<input type=submit value="Save">
</div></td>
</tr>
</table>
</form>
</body>
</html>
== cid-store.php ==
<HTML>
<HEAD>
<TITLE>Storing Asterisk CID data</TITLE>
</HEAD>
<BODY>
<h1>Asterisk phone book</h1>
<?php
set_time_limit(5);
if ($PhoneNumber <> "" && $PhoneName <> "") {
// Note: this PHP script runs as user "apache"!
// system("whoami > /tmp/info");
system("sudo /usr/sbin/asterisk -rx " . escapeshellarg("database put
cidname $PhoneNumber \"$PhoneName\"") . " &> /tmp/error");
print "Successfully stored <b>$PhoneNumber</b> as
<b>$PhoneName</b>.";
} else {
print "Please enter both phone number and name!";
}
?>
</BODY>
</HTML>
| |
| DJ Craig 2005-01-27, 8:56 pm |
| Heres the error:
if ($PhoneNumber <> "" && $PhoneName <> "")
refering to the POST variable just as $ and then the name of the form
field is obsolete. It was removed in newer versions of PHP for
security reasons.
Instead, put:
if ($_POST("PhoneNumber") <> "" && $_POST("PhoneName") <> "")
$_POST is an array on any page reached from a form with method="POST"
By the way, it would probably be better to check that they have entered
something in both form fields on the cid-form.htm page. This way,
their browser doesn't erase what they have typed in when they press the
back button. Then on the PHP page, put:
if (isset($_POST("PhoneNumber")) && isset($_POST("PhoneName")))
the isset() function returns false only if the variable doesn't exist;
it returns true for a variable that exists, but has no content, like
"". This way you can have a different error message for people who try
to access cid-store.php by typing it directly into their browser, or
from their favorites or history.
| |
| Geoff Berrow 2005-01-27, 8:56 pm |
| I noticed that Message-ID:
<1106850956.359386.85450@z14g2000cwz.googlegroups.com> from DJ Craig
contained the following:
>Instead, put:
>if ($_POST("PhoneNumber") <> "" && $_POST("PhoneName") <> "")
Not sure if round brackets work (never tried) but it's certainly more
normal to use square. I always use single quotes too.
And if one is set, they both will be. If you need to check if anything
has been entered you need to use empty()
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
| |
| Robert Rozman 2005-01-28, 3:57 pm |
|
"DJ Craig" <spit@djtricities.com> wrote in message
news:1106850956.359386.85450@z14g2000cwz.googlegroups.com...
> Heres the error:
> if ($PhoneNumber <> "" && $PhoneName <> "")
>
> refering to the POST variable just as $ and then the name of the form
> field is obsolete. It was removed in newer versions of PHP for
> security reasons.
>
> Instead, put:
> if ($_POST("PhoneNumber") <> "" && $_POST("PhoneName") <> "")
>
> $_POST is an array on any page reached from a form with method="POST"
>
>
> By the way, it would probably be better to check that they have entered
> something in both form fields on the cid-form.htm page. This way,
> their browser doesn't erase what they have typed in when they press the
> back button. Then on the PHP page, put:
> if (isset($_POST("PhoneNumber")) && isset($_POST("PhoneName")))
>
Hi,
thanks for hints. I followed you instructions and put
if (isset($_POST("PhoneNumber")) && isset($_POST("PhoneName")))
but now I get error :
Parse error: parse error, unexpected '(', expecting ',' or ')' in
/var/www/html/database/cid-store.php on line 11
Any further advice ?
Regards,
Rob.
| |
| Geoff Berrow 2005-01-28, 3:57 pm |
| I noticed that Message-ID: <tarKd.8606$F6.1576084@news.siol.net> from
Robert Rozman contained the following:
>
>"DJ Craig" <spit@djtricities.com> wrote in message
>news:1106850956.359386.85450@z14g2000cwz.googlegroups.com...
>Hi,
>
>thanks for hints. I followed you instructions and put
>if (isset($_POST("PhoneNumber")) && isset($_POST("PhoneName")))
>
>but now I get error :
>
>Parse error: parse error, unexpected '(', expecting ',' or ')' in
>/var/www/html/database/cid-store.php on line 11
>
>Any further advice ?
Here is a script I wrote earlier as part of a tutorial
http://www.ckdog.co.uk/phpcourse/2_..._structures.doc
It should give you an idea.
<html>
<head>
<title></title>
</head>
<body>
<?php
//let's catch all errors
error_reporting(E_ALL);
//if there is no input, display the form
if(!isset($_POST['send'])){
?>
<form method="POST" action="">
Enter Forename: <input type="textbox" name="forename" value="">
<br><br>
Enter Last name: <input type="textbox" name="lastname" value="">
<br><br>
<input type="submit" name="send" value="Send"><br><br>
</form>
<?php
}
//if there is input but either forename or lastname is empty
elseif(empty($_POST['forename']) || empty($_POST['lastname'])){
print "Please enter both a forename and a last name<br>";
print "<a href=\"".$_SERVER['PHP_SELF']."\">Back</a>";
}
//if there is input and neither value is empty
else{
print "Forename: ".$_POST['forename']."<br>";
print "Last name: ".$_POST['lastname'];
}
?>
</body>
</html>
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
| |
| Dani CS 2005-01-28, 3:57 pm |
| Robert Rozman wrote:
> "DJ Craig" <spit@djtricities.com> wrote in message
> news:1106850956.359386.85450@z14g2000cwz.googlegroups.com...
>
>
> Hi,
>
> thanks for hints. I followed you instructions and put
> if (isset($_POST("PhoneNumber")) && isset($_POST("PhoneName")))
DJ Craig did some typos. The line above should read
if (isset($_POST["PhoneNumber"]) && isset($_POST["PhoneName"]))
as noted by Geoff Berrow.
>
> but now I get error :
>
> Parse error: parse error, unexpected '(', expecting ',' or ')' in
> /var/www/html/database/cid-store.php on line 11
>
> Any further advice ?
>
> Regards,
>
> Rob.
>
>
| |
| DJ Craig 2005-01-28, 3:57 pm |
| My bad...
but if u use double quotes u can put variable names in the quotes like
echo "You have $lives lives left.";
|
|
|
|
|