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
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
Share on other sites

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.