Dysan Posted November 10, 2007 Share Posted November 10, 2007 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 More sharing options...
pocobueno1388 Posted November 10, 2007 Share Posted November 10, 2007 <?php $var = $_POST['field1'].$_POST['field2'].$_POST['field3']; echo $var; ?> Give that a try. Link to comment https://forums.phpfreaks.com/topic/76797-store-3-as-1/#findComment-388820 Share on other sites More sharing options...
kratsg Posted November 11, 2007 Share Posted November 11, 2007 add a mysql_real_escape_string($variable) for all user-inputs to keep yourself safe from sql injections. Link to comment https://forums.phpfreaks.com/topic/76797-store-3-as-1/#findComment-388827 Share on other sites More sharing options...
AndyB Posted November 11, 2007 Share Posted November 11, 2007 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 More sharing options...
cooldude832 Posted November 11, 2007 Share Posted November 11, 2007 how was the north pole andy? Link to comment https://forums.phpfreaks.com/topic/76797-store-3-as-1/#findComment-388890 Share on other sites More sharing options...
AndyB Posted November 11, 2007 Share Posted November 11, 2007 how was the north pole andy? fine - www.andybowers.com/alert Link to comment https://forums.phpfreaks.com/topic/76797-store-3-as-1/#findComment-388897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.