473,394 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Cannot send parameters

Hey all,

I'm new to PHP and i'm just trying to test out a simple script as follows:

[PHP]
#!C:/Program Files/PHP/PHP.exe
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

//import_request_variables("gpc","mvar_");

print "Content-type: text/html\n\n";

if (isset($_GET['name'])) {
print "Hello, " . $_GET['name'];
}
else {
print <<<HTML
<form action="http://pladdypants.home/cgi-bin/ch6ex.php" method="get">
Name: <input type="text" name="name" />
<input type="submit" value="Submit" />
</form>
HTML;
}
?>
[/PHP]>

I've worked at this and it runs fine, however when i click submit with a name in the field, it doesn't show up when it reruns. The url changes and it has a parameter defined there, but nothing prints to the screen. Am I overlooking something simple here? I've tried lots of different things and no luck.

I'm using XP Pro, mozilla browser, apache 2.2. This is just my computer as a server and i'm accessing local files. Is this an issue with my code, how PHP was installed, how my server is set up? Sorry for such a silly question, I'm sure I'm doing something very basic and stupid...Any help would be greatly appreciated.

-Pladdy
Nov 5 '08 #1
14 2476
code green
1,726 Expert 1GB
There is no such variable as $name; [PHP]if (isset($_GET['name'])) {
print "Hello, " . $name; [/PHP] Unless you have GLOBALS switched on, which you shouldn't,
you need to read the URL variables into the variable [PHP]$name = $_GET['name'])) [/PHP]
Nov 5 '08 #2
Hey, I saw that error in the code and fixed it right before you responded. However even when i use
[PHP]
$name = $_GET['name'];
print $name;
[/PHP]>

I still get nothing...

-pladdy
Nov 5 '08 #3
Hey, I saw that error in the code and fixed it right before you responded. However even when i use
[PHP]
$name = $_GET['name'];
print $name;
[/PHP]>

I still get nothing...

-pladdy
Also, here's the readout i get for the line that should set $name = to $_GET['name']
"Notice: Undefined index: name in C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\ch6ex.php on line 9"

So i see it being passed in the url, but it's like it's not ending up in $_GET...
-pladdy
Nov 5 '08 #4
code green
1,726 Expert 1GB
Then I suspect your HTML [PHP]else {
print <<<HTML
<form action="http://pladdypants.home/cgi-bin/ch6ex.php" method="get">
Name: <input type="text" name="name" />
<input type="submit" value="Submit" />
</form>
HTML; [/PHP] I don't understand how this
runs fine
.
How are you writing to the browser?
PHP - No quotes
HTML - No closing php tag
Or that other method of bulk printing with the <<< syntax
Nov 5 '08 #5
Then I suspect your HTML [PHP]else {
print <<<HTML
<form action="http://pladdypants.home/cgi-bin/ch6ex.php" method="get">
Name: <input type="text" name="name" />
<input type="submit" value="Submit" />
</form>
HTML; [/PHP] I don't understand how this .
How are you writing to the browser?
PHP - No quotes
HTML - No closing php tag
Or that other method of bulk printing with the <<< syntax
Hi again,
1) By 'runs fine' i mean it actually runs without critical errors that kill it.
2) I'm trying to write the end result (Hello, 'name') to the browser just using
[PHP]
print "Hello, " . $_GET['name'];
[/PHP]
So, i either want the browser to show my simple form, using the here document (HTML), or if it has a value from the form, to just print "Hello, " $_GET['name'].

The php script i posted originally is the entire script - is that missing something critical that i've overlooked, like end quotes, or end tags?

thanks again, -pladdy
Nov 5 '08 #6
Atli
5,058 Expert 4TB
Hi.

There are few things that jump at me when I consider you code.
  • Line #1.
    If this is in fact being run through a Apache server, this line shouldn't be needed. The Apache server should know where the PHP executable is and know to execute .php files using it.
    I'm not sure if this actually matters, but I thought it worth mentioning :)
  • Line #8.
    Why do you *print* a HTTP header to the output?
    It shouldn't be sent as a header, but it could be throwing the browser off, which might be causing some problems.
  • Line #15. The action property of your form.
    I assume this URL work on your local network?
    If you are using your own computer to host this, try changing it to:
    Expand|Select|Wrap|Line Numbers
    1. http://localhost/cgi-bin/ch6ex.php
    Again, I don't know if this will actually change anything, but this is what one typically does to connect to a local HTTP server.
  • And lastly, why do you use the GET protocol? Is the name value being passed on the URL as it should?
    I would try using the POST protocol instead, and of course using the $_POST super-global rather than $_GET.
Nov 5 '08 #7
Hey there,

Line #1.
I removed the shebang but then it won't run, so i put it back.

Line #8.
I tried removing this and just putting the following code:

[PHP]
#!C:/Program Files/PHP/PHP.exe
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>PHP Test</title>
</head>
<body>

<?php
//print "Content-type: text/html\n\n";

if (isset($_GET["name"])) {
print "Hello, " . $_GET["name"];
}
else {
print <<<HTML
<form action="http://localhost/cgi-bin/ch6ex.php" method="get">
Name: <input type="text" name="name" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
HTML;
}
?>
[/PHP]

But this generates a 500 error and my browser won't open it. I checked the error logs and it's due to a malformed header.

Line #15.
I changed this and it's working fine.

Finally, i'm using get so i can verify that the parameter is being passed which it is. I'm just confused as to how i'm messing this up so badly. It seems from everything I read most people don't have any issues with getting parameters to pass in a script as simple as this.
Nov 6 '08 #8
Atli
5,058 Expert 4TB
Thats all extremely odd.
I have never heard of Apache needing anything like that first line in order to work.

Try this script. See what it does:
Expand|Select|Wrap|Line Numbers
  1. <pre>
  2. <?php
  3.   print_r($_GET);
  4. ?>
  5. </pre>
  6. <form action="?" method="get">
  7.   <input type="text" name="test"><br>
  8.   <input type="submit">
  9. </form>
  10.  
Very simple, but effective.
If your server is working properly, this should simply print GET variables at the top.
Nov 6 '08 #9
Hey again,

I tried it twice, here are the error outputs from error log:

[Wed Nov 05 22:13:01 2008] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/Text1.php

...added a shebang line and got this error:
[Wed Nov 05 22:13:45 2008] [error] [client 127.0.0.1] malformed header from script. Bad header=Array: Text1.php

So i changed the code to this, and it runs but no parameters pass:
[PHP]
#!C:\Program Files\PHP\PHP.exe
<?php
print "Content-type: text/html\n\n";
print_r($_GET);
?>
<form action="?" method="get">
<input type="text" name="test"><br>
<input type="submit">
</form>
[/PHP]

It outputs "Array()", then the input and submit button.

Perhaps this all means i set up apache poorly? I installed it from a windows installer and have done little to the config files. Really my only goal was to create a basic local server to learn php...

-pladdy
Nov 6 '08 #10
Atli
5,058 Expert 4TB
Yes. This would mean that it is in fact your Apache server that is causing the problem.

How did you install PHP, and what version did you install?

On the rare occasions that I set up PHP on a Windows machine, I usually just use the MSI installers. I set up Apache first and then have the PHP installer set up the Apache config for it.

You can try editing your Apache's httpd.conf file.
Adding these lines at the end might help:
Expand|Select|Wrap|Line Numbers
  1. PHPIniDir "C:/Program Files/PHP/"
  2. LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"
  3. AddType application/x-httpd-php .php
  4.  
Remember to change the paths to if they don't match your setup.
Nov 6 '08 #11
ak1dnar
1,584 Expert 1GB
Thread title changed from "parameter wont send (newbie error, sorry)" to "Cannot send parameters" .This will be better than earlier. Please read the posting guidelines provided in FAQ section.

MODERATOR
Nov 6 '08 #12
code green
1,726 Expert 1GB
Are you actually running this in localhost?
Nov 6 '08 #13
Hey everyone,

I read posting guidelines, thank you for changing the title. I made the changes suggested by Atli. Code Green, I am running this as localhost. Unfortunately I'm still not getting any parameters passed. I think the consensus is it has to do with the Apache setup. Unless anyone has other suggestions, perhaps I should post on the Apache forum?

I installed Apache 2.2.10 first, then PHP 5.2.6. I used windows installers for both. When they installed I just selected all defaults. Php set up apache, and when prompted i selected the 2.2x option. Hope this helps,

Thanks again all,

-Pladdy
Nov 6 '08 #14
It was a setup error in the php.ini file. I was placing the php files in the cgi-bin folder of my server rather than htdocs folder. Once the scripts are moved to htdocs they work fine. Thanks all for helping me look in the right direction.

-pladdy
Nov 12 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: simon | last post by:
Always when I need data reader in my programs, I simply have functions, which creates it for me: Dim rdr As SqlDataReader dim sql as string sql="myStoredProcedure" rdr =...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Kevin Nechodom | last post by:
I have a table with 3 fields: UnitTime, Unit, and UnitCount in an MDB database. I have a query, qryWriteUnitOccupancy, that appends a record to that table using 2 parameters: TimePoint, and...
2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
11
by: Leon | last post by:
I have six textbox controls on my webform that allows the user to enter any numbers from 1 to 25 in any order. However, I would like to sort those numbers from least to greatest before sending them...
1
by: alan | last post by:
in my project there are 5 textbox : tbOrderid, tbSeqNum, tbFoodCode, tbFoodDesc and tbPrice 9 button: btInsert, btdelete, btUpdate, btClear, btBind, btFirst, btPrevious, btNext and btLast i...
1
by: Caroline | last post by:
I am trying to update a record though a stored procedure and parameters, but I keep getting this error: Additional information: Argument 'Prompt' cannot be converted to type 'String'. Any...
0
by: Alexiel | last post by:
Hi, i have a problem, I have a Java Client and i call my webservice on ..NET. This run perfectly just except when i send parameters don't work fine. I send my code : This is my java...
2
by: karenkksh | last post by:
Hi, The user_id is set as primary key. "Cannot insert the value NULL into column 'user_id', table 'C:\DOCUMENTS AND SETTINGS\KAREN\MY DOCUMENTS\VISUAL STUDIO...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.