Page 1 of 1

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

Posted: Mon Mar 09, 2009 9:03 pm
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.

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

Posted: Mon Mar 09, 2009 10:26 pm
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.

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

Posted: Tue Mar 10, 2009 10:07 am
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.