Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2004, 11:10 AM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default read data into a TEXTBOX

here again ive knocked up something quick :)

im trying to read data into a textbox
i thought the code below could manage it
but i dont think so

can some one give me a solution.
the books i have shows
how to read data from textboxs and
how to put data into listboxs

<html>
<head>
<title>quick knocker</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
  <input type="text" name="testbox" size="20" maxlength="20">
  testbox
</form>
<PHP

$value="am i in the box";
$testbox=$value;

?>

</body>
</html>


 
Old January 10th, 2004, 02:55 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

You use the value attribute.
What you were doing looked like JavaScript, PHP is not capable of accessing the document object model.

For your example:
<input type="text" name="testbox" size="20" maxlength="20" value="am i in the box">

To do it with a php variable:

<?php

$value= "am i in the box";
echo '<input type="text" name="testbox" size="20" maxlength="20" value="{$value}">';

?>

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 10th, 2004, 04:07 PM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i actually copied and pasted the code but evertime i run it
the result is {$value} inside of the text box
instead of the string itself

thanks for helping though some how to me your code looks right


cuwark

 
Old January 10th, 2004, 05:16 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Have you properly installed PHP?

What do you get when you run this:

<?php phpinfo(); ?>

Save as phpinfo.php

You should see a detailed output of configuration and environment settings.


: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 10th, 2004, 06:51 PM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yea ill give it a go plus in the mean time ill upload it to my webspace.

im sure it works, it must be a probs on my side.

ill let you know the out come in a few clicks

thanks again
cuwark

 
Old January 10th, 2004, 07:05 PM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok i did up load it to my web space and had the same result
the display box actually shows {$value}

i also tried it in maguma studio and got the same result

i dont know what to say really
now im scratching my head
can anyone help

the site is
http://www.enetpin.com/readbox.php

cuwark

 
Old January 11th, 2004, 02:22 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Oh, OK,
Its my bad.. It has something to do with me using single quotes on the string.

This one works:
<?php

$value= "am i in the box";
echo "<input type='text' name='testbox' size='20' maxlength='20' value='{$value}'>";

?>

I suppose it just means that variable substitution doesn't happen when using single quotes. Hmmm. Funny, been programming PHP all this time and never ran into that! Here are a couple of pages that explain why.

http://www.php.net/manual/en/language.variables.php
http://www.php.net/manual/en/languag....syntax.single

Sorry about that!
: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 11th, 2004, 02:25 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Oh and if you're determined to use double quotes in your output (I would stick with singles personally) but you can also just escape the quotes with the backslash character:

echo "<input type=\"text\" name=\"testbox\" size=\"20\" maxlength=\"20\" value=\"{$value}\">";

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 11th, 2004, 09:37 AM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks quesadilla5
you have help me alot i really needed that solution
i would of never figured it out but now you mention it
ill remember for life

double qoutes as wrappers and singles inside

thanks again
you are a topman

cuwark

 
Old January 12th, 2004, 04:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know if you've noticed, Rich (et al), but I typically use single quotes for ALL strings that don't have a variable substitution within it in the examples that I post. The reason is that PHP does NOT perform variable or escape character substitution in single-quoted strings, so it speeds things up to use them when I know that no variable exists. The speed increase is due to the fact that PHP doesn't need to perform more sophisticated parsing of the string before outputting it.

Some caveats -- the only escaped characters that PHP handles in single-quoted strings are the single-quote and the backslash For example, the character sequence \n in the following string is output literally as "backslash-n", not as a newline.

echo 'Hello \n world.';

A more complicated example:

echo 'He said, \'what is the root directory?\' I replied \"It\'s C:\\.\"\n';


This prints:
He said, 'what is the root directory?' I replied \"It's C:\.\"\n

Notice that the backslashes before the double quote characters and the newline 'n' character are NOT parsed as escape characters -- they're printed as literal backslashes.



Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to read data from textbox cancertropica Visual Studio 2005 4 November 12th, 2008 02:59 PM
Read from data grid watashi C# 2005 2 July 23rd, 2007 03:12 AM
Read data from USB san2308 General .NET 0 September 25th, 2006 08:02 AM
I can't read 1 line at a time from a textbox peterasimpson VB How-To 3 August 18th, 2006 11:45 AM
Read IE Data arindambarman .NET Framework 1.x 0 April 6th, 2006 04:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.