Using PHP to Print SELECT Results - Incomplete Data Returned

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith W. McCammon

    Using PHP to Print SELECT Results - Incomplete Data Returned

    So this little problem has stumped me for close to an hour, and I know it's
    something easy...

    I'm using PHP to select field values from a record in a MySQL database, and
    display those values inside of text boxes in a form (which is used to allow
    folks to update records). The SELECT statement:

    SELECT
    `last_name`,`fi rst_name`,`stre et`,`city`,`sta te`,`zip`,`area _code`,`phone`, `
    email`,`badge`
    FROM $table
    WHERE `last_name` = 'mccammon' AND `first_name` = 'keith'

    This is called via a standard connect string, the functional portion of
    which looks like this:

    $result=MYSQL_Q UERY($query) or die(mysql_error ());
    $data=mysql_fet ch_array($resul t);

    This all works great, *but* the `street` value normally looks like this:

    2000 L Street NW

    And when I use <? print $data[street] ?> to print the `street` value within
    the text box, all I see is:

    2000

    Apparently the first space in the field value is the end of the road, for
    some reason. I'm guessing this is something easy to handle, but I'm a
    novice here, so please go easy!

    Thanks

    Keith



  • Tom Thackrey

    #2
    Re: Using PHP to Print SELECT Results - Incomplete Data Returned


    On 13-Nov-2003, "Keith W. McCammon" <km@km.com> wrote:
    [color=blue]
    > I'm using PHP to select field values from a record in a MySQL database,
    > and
    > display those values inside of text boxes in a form (which is used to
    > allow
    > folks to update records). The SELECT statement:
    >
    > SELECT
    > `last_name`,`fi rst_name`,`stre et`,`city`,`sta te`,`zip`,`area _code`,`phone`, `
    > email`,`badge`
    > FROM $table
    > WHERE `last_name` = 'mccammon' AND `first_name` = 'keith'
    >
    > This is called via a standard connect string, the functional portion of
    > which looks like this:
    >
    > $result=MYSQL_Q UERY($query) or die(mysql_error ());
    > $data=mysql_fet ch_array($resul t);
    >
    > This all works great, *but* the `street` value normally looks like this:
    >
    > 2000 L Street NW
    >
    > And when I use <? print $data[street] ?> to print the `street` value
    > within
    > the text box, all I see is:
    >
    > 2000
    >
    > Apparently the first space in the field value is the end of the road, for
    > some reason. I'm guessing this is something easy to handle, but I'm a
    > novice here, so please go easy![/color]

    enclose the value in quotes <input ... value="<? print $data['street'];
    ?>"...>
    (You should also enclose street in apostrophies unless you've defined it as
    a constant or are using it in a quoted string.)

    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • kafooey

      #3
      Re: Using PHP to Print SELECT Results - Incomplete Data Returned

      On Thu, 13 Nov 2003 13:56:44 -0500, "Keith W. McCammon" <km@km.com>
      wrote:
      [color=blue]
      >SELECT
      >`last_name`,`f irst_name`,`str eet`,`city`,`st ate`,`zip`,`are a_code`,`phone` ,`
      >email`,`badg e`
      >FROM $table
      >WHERE `last_name` = 'mccammon' AND `first_name` = 'keith'[/color]

      You don't need the single quotes on the fieldnames.
      [color=blue]
      >And when I use <? print $data[street] ?> to print the `street` value within
      >the text box, all I see is:[/color]

      try...
      print $data["street"];



      kafooey
      - kafooey@nospam. yahoo.co.uk
      - http://www.pluggedout.com/blog

      Comment

      • Keith W. McCammon

        #4
        Re: Using PHP to Print SELECT Results - Incomplete Data Returned

        Thanks, Tom! That did the trick. Always the easy stuff that gets me...


        Comment

        • kafooey

          #5
          Re: Using PHP to Print SELECT Results - Incomplete Data Returned

          On Thu, 13 Nov 2003 19:18:34 GMT, kafooey <kafooey@nospam .yahoo.co.uk>
          wrote:
          [color=blue]
          >try...
          > print $data["street"];[/color]

          Of course... just re-read your question...

          You need to make sure you put your value within quotes in the form
          input tag.

          (see the other reply).

          I guess this is a case of RTFQ :)



          kafooey
          - kafooey@nospam. yahoo.co.uk
          - http://www.pluggedout.com/blog

          Comment

          • Keith W. McCammon

            #6
            Re: Using PHP to Print SELECT Results - Incomplete Data Returned

            Thanks for the suggestion. Enclosing this alone in quotes doesn't do it,
            but enclosing the value itself does.


            Comment

            Working...