473,403 Members | 2,284 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,403 software developers and data experts.

Heeeeeeeeeeeeeeeeeeeeeelp ! why this programme doesn't work?

look at this :
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action="test1.php" method="POST" id="form" >
<input type="text" id="tt" />
<input type="submit" value="submit" id="submit" />
</form>
</body>
</html>

I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.
Jun 14 '06 #1
11 1176
On Wed, 14 Jun 2006 21:09:17 +0800, Carl Anatorian wrote:
I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.


Because PHP picks "name" attribute, not "id" attribute. Try with this:
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action=<?=$_SERVER['PHP_SELF']?> method="POST" >
<input type="text" name="tt" />
<input type="submit" value="submit" name="submit" />
</form>
</body>
</html

--
http://www.mgogala.com

Jun 14 '06 #2
C.
Hi,

Let's try this :

<input type='text' name='tt' value=''>

instead of your <input type='text' ...> line.
C.
Carl Anatorian wrote:
look at this :
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action="test1.php" method="POST" id="form" >
<input type="text" id="tt" />
<input type="submit" value="submit" id="submit" />
</form>
</body>
</html>

I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.

Jun 14 '06 #3
Mladen Gogala wrote :
On Wed, 14 Jun 2006 21:09:17 +0800, Carl Anatorian wrote:
I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.


Because PHP picks "name" attribute, not "id" attribute. Try with this:
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action=<?=$_SERVER['PHP_SELF']?> method="POST" >
<input type="text" name="tt" />
<input type="submit" value="submit" name="submit" />
</form>
</body>
</html

thank you very much !!!!!!
But why does php only pick "name" attribute?
Jun 14 '06 #4
Mladen Gogala 写道:
On Wed, 14 Jun 2006 21:09:17 +0800, Carl Anatorian wrote:
I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.


Because PHP picks "name" attribute, not "id" attribute. Try with this:
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action=<?=$_SERVER['PHP_SELF']?> method="POST" >
<input type="text" name="tt" />
<input type="submit" value="submit" name="submit" />
</form>
</body>
</html

Another one :
<?php
if($_COOKIE['hello'] != "world") {
$result = setcookie("hello","world",60*10);
}
?>
<html>
<body> <?php
if(isset($_COOKIE['hello'])) {
echo "hello !";
}
?>
</body>
</html>

I think it will show "hello !" when I access it the second time, but it
never.Why? I don't disable my browser's cookies.
Jun 14 '06 #5
Carl Anatorian wrote:
But why does php only pick "name" attribute?


ID's not name, and it won't be sent along with the request, so it's not
the problem for PHP.
It's true that the new XHTML stop using name and use id instead, but
name still be used in inputs, textareas, and buttons.

Jun 14 '06 #6
Carl Anatorian schrieb:
[...]
Because PHP picks "name" attribute, not "id" attribute. Try with this: [...]

thank you very much !!!!!!
But why does php only pick "name" attribute?


These attributes have quite different meanings: name is for the key of
form submissions, while id is for DOM access, and has more restrictive
naming rules, and must be unique. These restrictions are not applicable
for the name attribute. These are valid:

<input type="radio" name="option" value="0">
<input type="radio" name="option" value="1">

<input type="checkbox" name="choice[]" value="0">
<input type="checkbox" name="choice[]" value="1">

<input type="text" name="friends[]" value="Tina">
<input type="text" name="friends[]" value="Ike">

While they all would cause validation errors if id was used instead of
name. Also stuff like getElementById("option") would not work if id was
not unique.

--
Markus
Jun 14 '06 #7
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carl Anatorian wrote:
But why does php only pick "name" attribute?


It's not PHP, it's HTML. Geez, read the specs:

http://www.w3.org/TR/html4/interact/forms.html#h-17.2

When a form is submitted for processing, some controls have their name
paired with their current value and these pairs are submitted with the
form. Those controls for which name/value pairs are submitted are called
successful controls.

- --
- ----------------------------------
Ivn Snchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Now listening to: Yuki Kajiura - Madlax Original Soundtrack 2 (2004) - [4]
Fall on you (2:13) (91%)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFEkBJY3jcQ2mg3Pc8RAhIXAJ9rOpfYq668/QCskdyqr61oMoOPeQCfV8Ll
XufBSAoPsPB800yktLISNs0=
=wqT8
-----END PGP SIGNATURE-----
Jun 14 '06 #8

Carl Anatorian wrote:
Heeeeeeeeeeeeeeeeeeeeeelp ! why this programme doesn't work?


The title for your post is probably not very descriptive. A better one
would be "Form doesn't work" or something like that. Luckily, because
of the nice people in the comp.lang.php group, you get away with it.

Jun 14 '06 #9
Carl Anatorian wrote:
Another one :
<?php
if($_COOKIE['hello'] != "world") {
$result = setcookie("hello","world",60*10);
}
?>
<html>
<body> <?php
if(isset($_COOKIE['hello'])) {
echo "hello !";
}
?>
</body>
</html>

I think it will show "hello !" when I access it the second time, but it
never.Why? I don't disable my browser's cookies.


Carl, setcookie returns boolean, so it would be prudent to check
whether it has actually happened. You should add something like:
if (!$result) { die("Better luck next time"); }
Second, cookies will NOT be sent if the HTML headers have already been
sent. Your heading (<html>) makes sure that they have been sent, so your
cookie will probably not be sent. You should do something like
<?php ob_start(); ?> before the HTML header.

--
Mladen Gogala
http://www.mgogala.com
Jun 14 '06 #10
Carl Anatorian wrote:
thank you very much !!!!!!
But why does php only pick "name" attribute?


I'll give you the answer from the movie "Who Framed Roger Rabbit": It
was drawn that way.

--
Mladen Gogala
http://www.mgogala.com
Jun 14 '06 #11
"the DtTvB" <me********@gmail.com> wrote in message
news:11*********************@f6g2000cwb.googlegrou ps.com...
Carl Anatorian wrote:
But why does php only pick "name" attribute?


ID's not name, and it won't be sent along with the request, so it's not
the problem for PHP.
It's true that the new XHTML stop using name and use id instead, but
name still be used in inputs, textareas, and buttons.

That's actually quite insane, if you think about radio buttons. more than
one elements may share the same name while their id's must be distinct. Now
if you have a radiobutton group like so:

<input type="radio" name="foo" id="foo_1" value="1">
<input type="radio" name="foo" id="foo_2" value="2">
<input type="radio" name="foo" id="foo_3" value="3">

Traditionally the name is submitted, so in the backend you just check the
value of form-variable named foo and you know what was selected. Now if you
send id instead of name, first you need to go through all the id's to see
which is set, then get the value of it. To me this makes no sense. The name
binds the control group together while the id distincts individual controls.

What's the point again fixing something that isn't broken? Actually breaking
something that works perfectly. I've always thought it like this: id is for
client-side, name is for server side. The id is used with javascripts, like
getElementById when accessing a certain control and binding lables to
controls. The name is what the server side should see, clear and simple.

So what's this new XHTML that is going to destroy a perfectly working
system?

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jun 15 '06 #12

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

Similar topics

3
by: XMLSDK | last post by:
I have written a programme to receive the HTML code from a URL http://www.pru.com.hk/ But I dunno why it doesn't work. It can only receive the beginning few lines: <!-- i n clude file="BB.asp"...
0
by: cm012b5105 | last post by:
Hello i want to put an interactive text programme in to a graphical box this is a small section of my text programme s = raw_input ("Hello whats your name? ") if s=='melvyn': print "your my...
2
by: NDAKI MBOULET | last post by:
J'ai un problme pour crire un programme. Voici mon sujet: Ecrire en c++ un programme qui reoit en entre une suite d'instruction encadres par les mots cls BIBODLE et LISUK dans un langage...
1
by: nigel | last post by:
hi i have wrote an interactive programme,this is a small section of it. #This is my first programme writing in python s = raw_input ("hello what's your name? ") if s=='carmel': print "Ahh the...
0
by: bog39 | last post by:
We have z/os and DB/2 V. 8 running. I try to create a new UDF using the command CREATE FUNCTION: CREATE FUNCTION CNGETADR (INTEGER) RETURNS CHAR(50) EXTERNAL NAME CNADR001 ...
4
by: hn.ft.pris | last post by:
####################################### ........ void argParser(int, char**); int main(int argc, char** argv){ argParser(argc, argv); return 1; } void argParser(int argc, char** argv){
1
by: arnuld | last post by:
this is "word counting" example programme from K&R2 section 1.5.4. it runs without any error/warning but does not work properly, i.e. the OUTPUT 1 should be: NEWLINES: 1 WORDS: 1 CHARs: 5
4
by: Spiros Bousbouras | last post by:
I got the following programme from an old post: http://tinyurl.com/53oa6o It was given at a job interview and the question was "The following program works, but what is a potential problem with...
7
by: rashthreat | last post by:
im unable 2 run programme in c++ when i try 2 execute it the output doesn't appears i hv reinstalled it again but the programme still persist.
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.