combining the value of 2 alphanumberic variables in html

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rlm51
    New Member
    • Mar 2007
    • 29

    combining the value of 2 alphanumberic variables in html

    in a form I am declaring the value of two variables, firstname and lastname

    in the code, I want to combine the value of those two variables

    example:

    firstname = Sam
    lastname = Spade

    comboname = Spade, Sam

    please forgive my ignorance, but reference manuals are not what they used to be.
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    You can't do this with html. You would need javascript or a programming language on the server side.

    Comment

    • AricC
      Recognized Expert Top Contributor
      • Oct 2006
      • 1885

      #3
      Originally posted by rlm51
      in a form I am declaring the value of two variables, firstname and lastname

      in the code, I want to combine the value of those two variables

      example:

      firstname = Sam
      lastname = Spade

      comboname = Spade, Sam

      please forgive my ignorance, but reference manuals are not what they used to be.
      What language do you want to combine these in? Like said above a server side language will allow you to do something with the data ie.. add it to a database whereas you could use javascript to combine them, but once the page goes away so will the combination.

      Comment

      • rlm51
        New Member
        • Mar 2007
        • 29

        #4
        Originally posted by AricC
        What language do you want to combine these in? Like said above a server side language will allow you to do something with the data ie.. add it to a database whereas you could use javascript to combine them, but once the page goes away so will the combination.

        I am using php and mysql

        thanks for any help you can give.

        Comment

        • AricC
          Recognized Expert Top Contributor
          • Oct 2006
          • 1885

          #5
          Originally posted by rlm51
          I am using php and mysql

          thanks for any help you can give.
          I'll move your post to the PHP forum but "." (period should concatenate).


          Aric

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            [PHP]$firstname = 'Sam';
            $lastname = 'Spade';

            $comboname = $lastname.','.$ firstname;[/PHP]

            Comment

            • rlm51
              New Member
              • Mar 2007
              • 29

              #7
              This is the code I came up with ...
              <?php
              //Combine cusfirst and cuslast into cusname and input into table
              $cusfirst = $_POST['cusfirst'];
              $cuslast = $_POST['cuslast'];
              $cusname = ($cuslast.', '.$cusfirst);
              input name="cusname" type="hidden" name="cusname" value="$cusname ";
              ?>

              I am getting a:

              Parse error: parse error, unexpected T_STRING

              on the input statement...

              HELP!

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                This is a good start, but what you really meant to do was this:
                [PHP]
                <?php
                //Combine cusfirst and cuslast into cusname and input into table
                $cusfirst = $_POST['cusfirst'];
                $cuslast = $_POST['cuslast'];
                $cusname = ($cuslast.', '.$cusfirst);
                echo '<input name="cusname" type="hidden" name="cusname" value="'.$cusna me.'">';
                ?>
                [/PHP]
                Notice the echo statement, and how I handled including the variable in it.

                Originally posted by rlm51
                This is the code I came up with ...
                <?php
                //Combine cusfirst and cuslast into cusname and input into table
                $cusfirst = $_POST['cusfirst'];
                $cuslast = $_POST['cuslast'];
                $cusname = ($cuslast.', '.$cusfirst);
                input name="cusname" type="hidden" name="cusname" value="$cusname ";
                ?>

                I am getting a:

                Parse error: parse error, unexpected T_STRING

                on the input statement...

                HELP!

                Comment

                • rlm51
                  New Member
                  • Mar 2007
                  • 29

                  #9
                  Originally posted by Motoma
                  This is a good start, but what you really meant to do was this:
                  [PHP]
                  <?php
                  //Combine cusfirst and cuslast into cusname and input into table
                  $cusfirst = $_POST['cusfirst'];
                  $cuslast = $_POST['cuslast'];
                  $cusname = ($cuslast.', '.$cusfirst);
                  echo '<input name="cusname" type="hidden" name="cusname" value="'.$cusna me.'">';
                  ?>
                  [/PHP]
                  Notice the echo statement, and how I handled including the variable in it.

                  I tried your suggestion and the error went away but now only a null value is being inserted into the database.

                  This is the code as I entered it:

                  <?php
                  //Combine cusfirst and cuslast into cusname and input into table
                  $cusfirst = $_POST['cusfirst'];
                  $cuslast = $_POST['cuslast'];
                  $cusname = ($cuslast.', '.$cusfirst);
                  echo '<input type="hidden" name="cusname" value="'.$cusna me.'">';
                  ?>

                  the value of cusfirst and cuslast are being input in a form above the php code.
                  the php section is at the very bottom of the code.

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Take a look at the HTML being generated. Is the hidden value correctly populated? If so, then you have a problem with your INSERT SQL statement. If not, then you are not properly getting the values from the form.

                    Comment

                    • rlm51
                      New Member
                      • Mar 2007
                      • 29

                      #11
                      Originally posted by Motoma
                      Take a look at the HTML being generated. Is the hidden value correctly populated? If so, then you have a problem with your INSERT SQL statement. If not, then you are not properly getting the values from the form.
                      The values of cusfirst and cuslast are also input into the database, and since they populate correctly I can only assume that part is proper. I am using this php code to concatenate the two variables into cusname (re: Smith, John) in order to populate a drop-menu for locating the right customer in another page. I just wanted to prevent the user from having to enter the name twice.
                      RLM1

                      Comment

                      • Motoma
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3236

                        #12
                        Originally posted by rlm51
                        The values of cusfirst and cuslast are also input into the database, and since they populate correctly I can only assume that part is proper. I am using this php code to concatenate the two variables into cusname (re: Smith, John) in order to populate a drop-menu for locating the right customer in another page. I just wanted to prevent the user from having to enter the name twice.
                        RLM1
                        You didn't answer my question: was it correctly populated in the hidden input field's HTML?
                        If all you want to do is insert the value, just do something like this:
                        [PHP]
                        mysql_query("IN SERT INTO character (firstname, lastname, fullname) VALUES ( '$cusfirst', '$cuslast', '$cuslast, $cusfirst')");
                        [/PHP]

                        OR EVEN BETTER: don't even store that information, create it in the select:

                        Code:
                        SELECT firstname, lastname, CONCAT(CONCAT(lastname, ", "), firstname) AS fullname FROM characters

                        Comment

                        • rlm51
                          New Member
                          • Mar 2007
                          • 29

                          #13
                          Originally posted by Motoma
                          You didn't answer my question: was it correctly populated in the hidden input field's HTML?
                          If all you want to do is insert the value, just do something like this:
                          [PHP]
                          mysql_query("IN SERT INTO character (firstname, lastname, fullname) VALUES ( '$cusfirst', '$cuslast', '$cuslast, $cusfirst')");
                          [/PHP]

                          OR EVEN BETTER: don't even store that information, create it in the select:

                          Code:
                          SELECT firstname, lastname, CONCAT(CONCAT(lastname, ", "), firstname) AS fullname FROM characters

                          There are 74 fields in the table all populated by a html form except for "cusname." I've only been writing php code for 3 weeks, so please be patient with me. Is there a way to populate only that one field without creating a seperate entry. If I use the insert command, it creates another db entry completely. I need to populate cusname along with the other 73 fields I am populating in html. Since I can't concatenate the cusfirst, cuslast fields in html, (or can I), I have to use php.

                          Comment

                          • Motoma
                            Recognized Expert Specialist
                            • Jan 2007
                            • 3236

                            #14
                            Google the SQL UPDATE syntax.

                            Comment

                            • rlm51
                              New Member
                              • Mar 2007
                              • 29

                              #15
                              Originally posted by Motoma
                              Google the SQL UPDATE syntax.
                              first of all I want to thank you for your kindness

                              Here is the command I have come up with:

                              UPDATE tbl_customer SET cusname = CONCAT(cuslast, ", " cusfirst);

                              can I execute this within dreamweaver 8 code

                              RLM51

                              Comment

                              Working...