Jump to content

Store 3 as 1


Dysan

Recommended Posts

How do i store data from three textboxs, as one field?

e.g.

 

If textbox 1 contains "one", textbox 2 contains "two", and textbox 3 contains "three", then the field should contain "onetwothree".

 

 

<?php

$sql="INSERT INTO Person (Firstname, Lastname, Sex)
VALUES
('$_POST[Firstname]','$_POST[Lastname]','$_POST[sex]')";

if (!mysql_query($sql,$con))
{
  die(mysql_error());
}
echo $_POST[Name] . "'s Record Added Successfully!";

mysql_close($con)
?>

Link to comment
https://forums.phpfreaks.com/topic/76797-store-3-as-1/
Share on other sites

It's hard to imagine any benefit to concatenating three pieces of different data into one variable. Seesm like you're just making trouble for yourself in the future when you decide you want to display data for a particular value, e.g. every record with the same sex or same first name.

 

If you really must concatenate the data, I'd recommend adding a delimiter character between the individual values: then one|two|three can be split into its original components since you know where each value ends and the next begins ... but then you'll realise it would have been better not to concatenate them in the first place.

Link to comment
https://forums.phpfreaks.com/topic/76797-store-3-as-1/#findComment-388863
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.