[PHP] Inserting from multiple textboxes in 1 MySQL tbl cell

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
TAViX
Forum Newbie
Posts: 13
Joined: Thu Feb 12, 2009 6:35 pm

[PHP] Inserting from multiple textboxes in 1 MySQL tbl cell

Post by TAViX »

Ok, this is very simple question actualy.

I have 3 textboxes: Sur_name, Middle_name and Last_name, but 1 cell called name in MySQL table. The question is how to insert those 3 values in 1 cell??
Thanks in advance.

Here is my current code sample from my script:

Code: Select all

 
 
$sn = $_POST['sur_name'.$i]; // Sur Name
$gn = $_POST['given_name'.$i]; // Given Name
$mn = $_POST['middle_name'.$i]; // Middle Name
$other_stuff = $_POST['other_stuff'.$i]; // Other Entries
 
 mysql_query("INSERT INTO a 
        (a.name, a.other_stuff)
        VALUES ('".clean($sn)." ".clean($gn)." ".clean($gn)."', '".clean($other_stuff)."')")
        or die(mysql_error());
 
 
Sure, I have other values but I've delete them only to show what I'm interested of.

Thank you again for your help.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: [PHP] Inserting from multiple textboxes in 1 MySQL tbl cell

Post by califdon »

Databases don't have cells.

The very first rule of database structure is that every column in a table must contain '"atomic" values, meaning that they cannot be divided into multiple values. It's called First Normal Form or 1NF. Thus, storing 3 parts of a name in the same table column is always wrong.

That's probably not what you want to hear, but this is a professional PHP and database developers' forum and most of us will tell you like it is.
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

Re: [PHP] Inserting from multiple textboxes in 1 MySQL tbl cell

Post by Paul Arnold »

What he said. I can't really see why you'd need to store the full name anyway. You'd be duplicating data unnecessarily.

You'd be much better off calling all 3 fields in your code and concatenating them from there.
Post Reply