473,385 Members | 1,465 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,385 software developers and data experts.

combining the value of 2 alphanumberic variables in html

29
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.
Mar 26 '07 #1
17 1861
drhowarddrfine
7,435 Expert 4TB
You can't do this with html. You would need javascript or a programming language on the server side.
Mar 26 '07 #2
AricC
1,892 Expert 1GB
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.
Mar 26 '07 #3
rlm51
29
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.
Mar 27 '07 #4
AricC
1,892 Expert 1GB
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
Mar 28 '07 #5
code green
1,726 Expert 1GB
[PHP]$firstname = 'Sam';
$lastname = 'Spade';

$comboname = $lastname.','.$firstname;[/PHP]
Mar 28 '07 #6
rlm51
29
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!
Mar 29 '07 #7
Motoma
3,237 Expert 2GB
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="'.$cusname.'">';
?>
[/PHP]
Notice the echo statement, and how I handled including the variable in it.

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!
Mar 29 '07 #8
rlm51
29
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="'.$cusname.'">';
?>
[/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="'.$cusname.'">';
?>

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.
Mar 29 '07 #9
Motoma
3,237 Expert 2GB
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.
Mar 29 '07 #10
rlm51
29
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
Mar 29 '07 #11
Motoma
3,237 Expert 2GB
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("INSERT 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:

Expand|Select|Wrap|Line Numbers
  1. SELECT firstname, lastname, CONCAT(CONCAT(lastname, ", "), firstname) AS fullname FROM characters
  2.  
Mar 29 '07 #12
rlm51
29
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("INSERT 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:

Expand|Select|Wrap|Line Numbers
  1. SELECT firstname, lastname, CONCAT(CONCAT(lastname, ", "), firstname) AS fullname FROM characters
  2.  

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.
Mar 29 '07 #13
Motoma
3,237 Expert 2GB
Google the SQL UPDATE syntax.
Mar 29 '07 #14
rlm51
29
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
Mar 29 '07 #15
Motoma
3,237 Expert 2GB
I have no experience with Dreamweaver, however, you can execute it inside PHP.
Mar 30 '07 #16
rlm51
29
I have no experience with Dreamweaver, however, you can execute it inside PHP.
This is what I am trying ... I placed this at the bottom of the code after the last </html>. no errors, but it is still posting a null value. Any thoughts. Hope you are having a pleasant Friday.

<?php
//Combine cusfirst and cuslast into cusname and input into table
$cusfirst = $_POST['cusfirst'];
$cuslast = $_POST['cuslast'];
$cusid = $_POST['cusid'];
$cusname = ('$cuslast'.', '.'$cusfirst');
mysql_query("UPDATE tbl_customer SET cusname='$cusname' WHERE primaryKey=$cusId");
?>
Mar 30 '07 #17
rlm51
29
I have no experience with Dreamweaver, however, you can execute it inside PHP.
For your future reference, this is the code that worked:

<?php
//Combine cusfirst and cuslast into cusname and input into table
$cusfirst = $_POST['cusfirst'];
$cuslast = $_POST['cuslast'];
$cusid = $_POST['cusid'];
$cusname = ("$cuslast".', '."$cusfirst");
mysql_query("UPDATE tbl_customer SET cusname='$cusname' WHERE cusfirst='$cusfirst' and cuslast='$cuslast'");
?>

The null seemed to be because I was using double quotes instead of single quotes and single quotes instead of double quotes.
Almost went nuts.

Thank you so very much for all of your help.

RLM51
Mar 31 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
2
by: sekdab | last post by:
I am a newbie at PHP and at a loss here. I need to iterate over rows in a database, and display them as editable fields in HTML. I can do this okay. However, I then need to be able to take a...
3
by: Magnus Lie Hetland | last post by:
If I want to specify both mode and source encoding using the -*- FOO -*- syntax in emacs -- how can I do that? Both insist on being on the second line of the file, yet I have found no way of...
3
by: Unregistered | last post by:
Hello! I came across two different scripts that I wanted to combine, and I thought I wa successful until I discovered a minor glitch. What was happening was that the page that was linked to...
7
by: Barry | last post by:
Hi all, I've noticed a strange error on my website. When I print a capital letter P with a dot above, using & #7766; it appears correctly, but when I use P& #0775 it doesn't. The following...
7
by: odysseus654 | last post by:
I have just discovered the "with" statement, which up until now I have only known as "that which should never be used". I would like to evaluate some commands (such as function definitions and the...
3
by: Roger | last post by:
Hi there I have several bigger applications programmed with the old ASP (vbscript). A lot of data is stored in the session object. Now I have to extend the application with new functionality...
5
by: Tristan Miller | last post by:
Greetings. Is it possible using HTML and CSS to represent a combining diacritical mark in a different style from the letter it modifies? For example, say I want to render Å‘ (Latin small letter...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.