Jump to content

Recommended Posts

Hello everyone,

 

I would like to let you know that I am brand new to PHP. I had someone help me in the past with PHP forms but that person is no longer helping. Here is what I cannot figure out:

 

I have a registration from with 3 fields entered independently. Lets say they are "first name", "middle name", and "last name." Right now I have them being dumped into database into 3 different columns, with respective names. How do I get all of them combined and entered in one column like "full name"?

 

Thanks for your help

Basically you take the same code you already have setup, but concatenate the posted info...

 

$fullname = $_POST['firstname'] . ' ' . $_POST['middlename'] . ' ' . $_POST['lastname'];

 

... and put it into a single column...same was as how it's done individually ...

I cannot seem to get it to work. Let's say my code looks like this:

 

mysql_query("INSERT INTO `test_test`.`Test_Registrations` (

`ID` ,

`first_name1`,

`mid_name1`,

`last_name1`

)

VALUES (

NULL ,

'$_POST[first_name1]' ,

'$_POST[mid_name1]' ,

'$_POST[last_name1]'

);")

or die(mysql_error()); 

//echo "Row inserted!";

?>

 

Where would I put the code?

first, create a field with the name 'full_name' as you stated, then use CrayonViolent's code to concatenate the posted info, and change the SQL query as required, ie.

 

$fullname = $_POST['firstname'] . ' ' . $_POST['middlename'] . ' ' . $_POST['lastname'];

mysql_query("INSERT INTO `test_test`.`Test_Registrations` (
`ID` ,
`full_name`
)
VALUES (
NULL ,
`{$full_name}`
)")
or die(mysql_error());

Ohh, that makes it easier. I got as far as entering the code and creating extra column in my database.

 

Now, I am getting:

 

Unknown column 'Joe bob Smith' in 'field list'

 

After the submission. What did I do wrong?

I have actually made it all one word. So, fullname is everywhere and not full_name.

 

Oh and I have accidentally used ` mark instead of '

 

Well, like I have said, I am new at this. But is works now. Thank you all...

--------------------------------------------------------------------------------

 

Now that I have that working how would I modify it so it graves me dash "-" followed by record number right after the full name?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.