pioneerx01 Posted October 4, 2009 Share Posted October 4, 2009 Hello everyone, I would like to let you know that I am brand new to PHP. I had someone help me in the past with PHP forms but that person is no longer helping. Here is what I cannot figure out: I have a registration from with 3 fields entered independently. Lets say they are "first name", "middle name", and "last name." Right now I have them being dumped into database into 3 different columns, with respective names. How do I get all of them combined and entered in one column like "full name"? Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/ Share on other sites More sharing options...
.josh Posted October 4, 2009 Share Posted October 4, 2009 Basically you take the same code you already have setup, but concatenate the posted info... $fullname = $_POST['firstname'] . ' ' . $_POST['middlename'] . ' ' . $_POST['lastname']; ... and put it into a single column...same was as how it's done individually ... Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930245 Share on other sites More sharing options...
CarbonCopy Posted October 4, 2009 Share Posted October 4, 2009 And don't forget to escape the string (For MySQL use mysql_real_escape_string). Wouldn't want some hackers breaking your site would we? Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930266 Share on other sites More sharing options...
pioneerx01 Posted October 4, 2009 Author Share Posted October 4, 2009 I cannot seem to get it to work. Let's say my code looks like this: mysql_query("INSERT INTO `test_test`.`Test_Registrations` ( `ID` , `first_name1`, `mid_name1`, `last_name1` ) VALUES ( NULL , '$_POST[first_name1]' , '$_POST[mid_name1]' , '$_POST[last_name1]' );") or die(mysql_error()); //echo "Row inserted!"; ?> Where would I put the code? Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930313 Share on other sites More sharing options...
mrMarcus Posted October 4, 2009 Share Posted October 4, 2009 first, create a field with the name 'full_name' as you stated, then use CrayonViolent's code to concatenate the posted info, and change the SQL query as required, ie. $fullname = $_POST['firstname'] . ' ' . $_POST['middlename'] . ' ' . $_POST['lastname']; mysql_query("INSERT INTO `test_test`.`Test_Registrations` ( `ID` , `full_name` ) VALUES ( NULL , `{$full_name}` )") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930328 Share on other sites More sharing options...
CarbonCopy Posted October 5, 2009 Share Posted October 5, 2009 mrMarcus you forgot to escape user input! Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930357 Share on other sites More sharing options...
pioneerx01 Posted October 5, 2009 Author Share Posted October 5, 2009 Ohh, that makes it easier. I got as far as entering the code and creating extra column in my database. Now, I am getting: Unknown column 'Joe bob Smith' in 'field list' After the submission. What did I do wrong? Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930379 Share on other sites More sharing options...
redarrow Posted October 5, 2009 Share Posted October 5, 2009 you didnt put the underscore in the varable did you? my_name _is_redarrow__only_guessing Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930380 Share on other sites More sharing options...
pioneerx01 Posted October 5, 2009 Author Share Posted October 5, 2009 I have actually made it all one word. So, fullname is everywhere and not full_name. Oh and I have accidentally used ` mark instead of ' Well, like I have said, I am new at this. But is works now. Thank you all... -------------------------------------------------------------------------------- Now that I have that working how would I modify it so it graves me dash "-" followed by record number right after the full name? Quote Link to comment https://forums.phpfreaks.com/topic/176475-combining-3-form-fields-into-one-record-and-dumping-to-database/#findComment-930404 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.