Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

MySQL, text box anomaly

by peppiv (Curate)
on Feb 06, 2002 at 18:03 UTC ( #143656=perlquestion: print w/replies, xml ) Need Help??

peppiv has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that connects to a MySQL DB (via DBI). I put the results into an array and print them to screen. When I print the results into a text box, it doesn't return the whole string. It only returns up to the first empty space. Any ideas on why this is happening and is there a way to over come it?

Here's some sample code:

while (my @result = $sth->fetchrow_array()) { print "@result[20]" }

This prints fine. But....

while (my @result = $sth->fetchrow_array()) { print "<input type=text name=address value=@result[0]>" }

This will return only "68" if the entire string were "68 calamity Ln." In the first example, it returns the entire string, so I know my results are returning the correct values.

Any Ideas?

peppiv

if it's not one thing it's a mother

Replies are listed 'Best First'.
foiled by HTML Quoting again. (boo)
by boo_radley (Parson) on Feb 06, 2002 at 18:13 UTC
    quote the answer.
    print "<input type=text name=address value=\"@result[0]\">"

    also, use $result[n] rather than @result[n], OK?

    update :
    You can find this stuff in the manual, you just need to know which one : http://www.w3.org/TR/html4/intro/sgmltut.html

    3.2.2 Attributes Elements may have associated properties, called attributes, which may have values (by default, or set by authors or scripts). Attribute/value pairs appear before the final ">" of an element's start tag. Any number of (legal) attribute value pairs, separated by spaces, may appear in an element's start tag. They may appear in any order. In this example, the id attribute is set for an H1 element:
    <H1 id="section1"> This is an identified heading thanks to the id attribute </H1>
    By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa. Authors may also use numeric character references to represent double quotes (") and single quotes ('). For double quotes authors can also use the character entity reference ". In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them. Attribute names are always case-insensitive. Attribute values are generally case-insensitive. The definition of each attribute in the reference manual indicates whether its value is case-insensitive. All the attributes defined by this specification are listed in the attribute index.
    update :
    Hi, Masem!
      Thanks boo_radley Works like a charm (or should I say quote?). I can't find answers like this in the effin manual.
Re: MySQL, text box anomaly
by Masem (Monsignor) on Feb 06, 2002 at 18:36 UTC
    Boo's got the answer, but technically, you should always quote the values of attributes in HTML, even if it's just a single word (it's required in XML, but even in HTML3 and 4, it's highly suggested, otherwise you have undefined behavior). Thus, you should be outputting:
    print "<input type=\"text\" name=\"address\" value=\"$result[0]\">";

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

      The qq operator is my close friend. It helps you escape from the escapes. :)

      print qq(<input type="text" name="address" value="$result[0]">\n);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://143656]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2021-06-19 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (91 votes). Check out past polls.

    Notices?