473,387 Members | 1,569 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,387 software developers and data experts.

using variables from form

Phi
Hi there,

I've just started learning php and I hope you guys could help me with
this problem. I've found a useful pice of code from a book to make a form
and I would like to use it. I would like to print the variables (input)
on the screen , but I can't make it work. I think I have to do something
with an array, but don't know what. I've tried

$field = $_POST['field'];
echo $field;

and also

$arr = $_POST['array'];
print_r($arr);

but it doesn't work.

Could some one show me what I'm missing?

Thanks a bunch!
Phi

########################### code ###################################

<?php

// new function
echo "<br><br><h4>second function</h4>\n";

function print_form($action="", $method="post")
{
if (empty($action)){return FALSE;}
echo "<form action=$action method=$method>\n";
$numargs = func_num_args();
for($i = 2; $i < $numargs; $i++)
{
echo "$i <input type = text name =". func_get_args($i) . ">
<br>\n";
}
echo "<input type=submit>";

echo "</form>";
}
print_form("autoform2.php", "", "field", "field2", "field3", "field4");
// testing if the variable exist...and it doesn't...
if(isset($_POST['field'])){
echo "exist";
}
else {
echo "does not exist!";
}

?>

########################### end code ##################################
Jul 17 '05 #1
7 2140
Phi wrote:
Hi there,

I've just started learning php and I hope you guys could help me with
this problem. I've found a useful pice of code from a book to make a form
and I would like to use it. I would like to print the variables (input)
on the screen , but I can't make it work. I think I have to do something
with an array, but don't know what. I've tried

$field = $_POST['field'];
echo $field;

and also

$arr = $_POST['array'];
print_r($arr);

but it doesn't work.

Could some one show me what I'm missing?

Thanks a bunch!

try to make a phpinfo(); on the page you submit to and see if the
variables are there (almost at the bottom).

--
Henrik Hansen
Jul 17 '05 #2
Henrik Hansen wrote:
$arr = $_POST['array'];
print_r($arr);


print_r($_POST); ??

Aphrael...
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #3
Phi
Henrik Hansen <hh****@fsck.dk> wrote in
news:R7********************@news000.worldonline.dk :
Phi wrote:
Hi there,

I've just started learning php and I hope you guys could help me with
this problem. I've found a useful pice of code from a book to make a
form and I would like to use it. I would like to print the variables
(input) on the screen , but I can't make it work. I think I have to
do something with an array, but don't know what. I've tried

$field = $_POST['field'];
echo $field;

and also

$arr = $_POST['array'];
print_r($arr);

but it doesn't work.

Could some one show me what I'm missing?

Thanks a bunch!

try to make a phpinfo(); on the page you submit to and see if the
variables are there (almost at the bottom).


I don't know if it's this what you mean. Thanks for your time again...
phpinfo();
################################################## #############
_REQUEST["Array"] test test test
_GET["Array"] test test test
_SERVER["HTTP_HOST"] localhost
_SERVER["HTTP_USER_AGENT"] Mozilla/5.0 (Windows; U; Windows NT 5.2; en-
US; rv:1.7) Gecko/20040626 Firefox/0.8
_SERVER["HTTP_ACCEPT"] application/x-shockwave-
flash,text/xml,application/xml,application/xhtml+xml,text/html;q=
0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/
*;q=0.1
_SERVER["HTTP_ACCEPT_LANGUAGE"] en-us,en;q=0.5
_SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate
_SERVER["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.7
_SERVER["HTTP_KEEP_ALIVE"] 300
_SERVER["HTTP_CONNECTION"] keep-alive
_SERVER["PATH"] C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\Sys tem32
\\Wbem;C:\\Program Files\\ATI Technologies\\ATI Control Panel;C:\\Program
Files\\Microsoft SQL Server\\80\\Tools\\BINN
_SERVER["SystemRoot"] C:\\WINDOWS
_SERVER["COMSPEC"] C:\\WINDOWS\\system32\\cmd.exe
_SERVER["PATHEXT"] .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
_SERVER["WINDIR"] C:\\WINDOWS
_SERVER["SERVER_SIGNATURE"] <address>Apache/2.0.50 (Win32) PHP/4.3.7
Server at localhost Port 80</address>
_SERVER["SERVER_SOFTWARE"] Apache/2.0.50 (Win32) PHP/4.3.7
_SERVER["SERVER_NAME"] localhost
_SERVER["SERVER_ADDR"] 127.0.0.1
_SERVER["SERVER_PORT"] 80
_SERVER["REMOTE_ADDR"] 127.0.0.1
_SERVER["DOCUMENT_ROOT"] Z:/www/apache
_SERVER["SERVER_ADMIN"] wh*********@nomail.com
_SERVER["SCRIPT_FILENAME"] Z:/www/apache/_faq/func/autoform2.php
_SERVER["REMOTE_PORT"] 2168
_SERVER["GATEWAY_INTERFACE"] CGI/1.1
_SERVER["SERVER_PROTOCOL"] HTTP/1.1
_SERVER["REQUEST_METHOD"] GET
_SERVER["QUERY_STRING"]
Array=test+test+test&Array=test+test+test&Array=te st+test+test&Array
=test+test+test&Array=test+test+test
_SERVER["REQUEST_URI"] /_faq/func/autoform2.php?
Array=test+test+test&Array=test+test+test&Array=te st+test+test&Array=test
+test+test&Array=test+test+test
_SERVER["SCRIPT_NAME"] /_faq/func/autoform2.php
_SERVER["PHP_SELF"] /_faq/func/autoform2.php
_SERVER["PATH_TRANSLATED"] Z:/www/apache/_faq/func/autoform2.php
_SERVER["argv"]

Array
(
[0] => Array=test
[1] => test
[2] => test&Array=test
[3] => test
[4] => test&Array=test
[5] => test
[6] => test&Array=test
[7] => test
[8] => test&Array=test
[9] => test
[10] => test
)

_SERVER["argc"] 11
_ENV["ALLUSERSPROFILE"] C:\\Documents and Settings\\All Users
_ENV["ClusterLog"] C:\\WINDOWS\\Cluster\\cluster.log
_ENV["CommonProgramFiles"] C:\\Program Files\\Common Files
_ENV["COMPUTERNAME"] TOWER
_ENV["ComSpec"] C:\\WINDOWS\\system32\\cmd.exe
_ENV["INCLUDE"] C:\\Program Files\\Microsoft Visual Studio .NET 2003\\SDK
\\v1.1\\include\\
_ENV["LIB"] C:\\Program Files\\Microsoft Visual Studio .NET 2003\\SDK
\\v1.1\\Lib\\
_ENV["NUMBER_OF_PROCESSORS"] 2
_ENV["OS"] Windows_NT
_ENV["Path"] C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\Sys tem32
\\Wbem;C:\\Program Files\\ATI Technologies\\ATI Control Panel;C:\\Program
Files\\Microsoft SQL Server\\80\\Tools\\BINN
_ENV["PATHEXT"] .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
_ENV["PROCESSOR_ARCHITECTURE"] x86
_ENV["PROCESSOR_IDENTIFIER"] x86 Family 6 Model 8 Stepping 3,
GenuineIntel
_ENV["PROCESSOR_LEVEL"] 6
_ENV["PROCESSOR_REVISION"] 0803
_ENV["ProgramFiles"] C:\\Program Files
_ENV["SystemDrive"] C:
_ENV["SystemRoot"] C:\\WINDOWS
_ENV["TEMP"] C:\\WINDOWS\\TEMP
_ENV["TMP"] C:\\WINDOWS\\TEMP
_ENV["USERPROFILE"] C:\\Documents and Settings\\NetworkService
_ENV["VS71COMNTOOLS"] C:\\Program Files\\Microsoft Visual Studio .NET 2003
\\Common7\\Tools\\
_ENV["windir"] C:\\WINDOWS
_ENV["AP_PARENT_PID"] 1384
################################################## #############
Jul 17 '05 #4
On 23 Jul 2004 11:53:39 GMT, Phi <ph*******@hotmail.com(remove)>
wrote:
Could some one show me what I'm missing?


1. you forgot to pass "post" to your function:

print_form("autoform2.php", "post", "field", "field2", "field3",
"field4");

would work with your script.

2. the result from func_get_args() is an array, you you have to change

echo "$i <input type = text name =". func_get_args($i) . ">

to this:

$fields= func_get_args();
echo "$i <input type = text name =". $fields[$i] . ">

With these changes your code works fine.

Regards

Marian

--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
Jul 17 '05 #5
Phi wrote:
Henrik Hansen <hh****@fsck.dk> wrote in
news:R7********************@news000.worldonline.dk :

Phi wrote:
Hi there,

I've just started learning php and I hope you guys could help me with
this problem. I've found a useful pice of code from a book to make a
form and I would like to use it. I would like to print the variables
(input) on the screen , but I can't make it work. I think I have to
do something with an array, but don't know what. I've tried

$field = $_POST['field'];
echo $field;

and also

$arr = $_POST['array'];
print_r($arr);

but it doesn't work.

Could some one show me what I'm missing?

Thanks a bunch!

try to make a phpinfo(); on the page you submit to and see if the
variables are there (almost at the bottom).

as you can see in your phpinfo() the variables are in _GET not in _POST,
so use _GET not _POST or change your submit method in the form.

--
Henrik Hansen
Jul 17 '05 #6
Phi
Marian Heddesheimer <22*************@spamgourmet.com> wrote in
news:m6********************************@4ax.com:
On 23 Jul 2004 11:53:39 GMT, Phi <ph*******@hotmail.com(remove)>
wrote:
Could some one show me what I'm missing?


1. you forgot to pass "post" to your function:

print_form("autoform2.php", "post", "field", "field2", "field3",
"field4");

would work with your script.

2. the result from func_get_args() is an array, you you have to change

echo "$i <input type = text name =". func_get_args($i) . ">

to this:

$fields= func_get_args();
echo "$i <input type = text name =". $fields[$i] . ">

With these changes your code works fine.

Regards

Marian


Thanks, your tips did the trick. I changed it and it worked! Now I have a
much better understanding of how the script and certain functions work.

Phi

##############code##########
/// new function
echo "<br><br><h4>second function</h4>\n";

function print_form($action="", $method="POST")
{
if (empty($action)){return FALSE;}
echo "<form action=$action method=$method>\n";
$numargs = func_num_args();
for($i = 2; $i < $numargs; $i++)
{
$fields= func_get_args();
echo $fields[$i]. "<input type = text name =".$fields[$i]. ">
<br>\n";

}
echo "<input type=submit>";

echo "</form>";
}
print_form("autoform2_2.php", "post", "field", "field2", "field3",
"field4");

//test the variables

$field = $_POST['field'];
echo $field;

$field2 = $_POST['field2'];
echo $field2;
Jul 17 '05 #7
Phi
Henrik Hansen <hh****@fsck.dk> wrote in news:r78Mc.27060$Vf.1476102
@news000.worldonline.dk:
Phi wrote:
Henrik Hansen <hh****@fsck.dk> wrote in
news:R7********************@news000.worldonline.dk :

as you can see in your phpinfo() the variables are in _GET not in _POST,
so use _GET not _POST or change your submit method in the form.


Thank you for your help. It works fine now with Marian's tips.
Thank for you tip to use phpinfo(). I'll make use of it more often.

Kind regards...

Phi
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert | last post by:
Hello, Can anyone help with this? On my online order form, I need to send a few variables to my credit-card processor. These variables are for non-secure customer comments, and will be sent...
13
by: Larry L | last post by:
I have a Module that declares several arrays as public, some string, some integers. I then have 2 forms. Form A is the main form, that loads on start-up, and has a command button to open Form B. On...
7
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the...
3
by: Steven K | last post by:
Hello, I am using an asp page (upload.asp) to gather information and to upload files to the web server using SoftArtisans SAUpload Tool. In the first page (upload.asp), I have a form for...
13
by: Steven Scaife | last post by:
I have decided to re-write the intranet site i created over a year ago. The coding is pretty awful and hard to read cos I made the mistake of not putting comments in or putting crappy comments in...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
3
by: DL | last post by:
Hi, Many questions have already been asked and answered about images in Access... But despite having searched, I have not found an answer to the following question... In my DB, several forms...
3
by: gw.boswell | last post by:
I have created a userform with textboxes for data entry. I also have a command button that calls a second useform. A user enters certain information in the first useform but if he/she wants to do...
3
accessbunnie
by: accessbunnie | last post by:
Hello Access Users! I am a bit of an Access novice and am currently creating a database and have come up against a huge (for me!) road block. I do not write in Access code and instead, tend to...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...

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.