stublackett Posted September 8, 2008 Share Posted September 8, 2008 Hi, I've got an SQL Insert Command and what I'd like it to do is put a space between each value when it is inserted into the Database Table Basically at the moment I've got the values firstname, secondname, address1, address2 When there inserted into the DB Table it goes as firstnamesecondnameaddress1address2 (As you can see no spaces) How do I use PHP and MySQL to space those values out? <?php // check if the form has been submitted if(isset($_POST['submit'])) { $sql = "INSERT INTO $db_table(experiencename,sender,numberofrecipients,reducedrate,total) values ('$description', '$senderforename' '$sendersurname' '$senderaddress' '$senderaddress1' '$sendertown' '$sendercounty' '$sendertelephone' '$senderemail','$numberofpeople','$reducedrate','$total')"; // Incase needed($result = mysql_query($sql ,$db)); ($result = mysql_query($sql ,$conn) or die(mysql_error())); } ?> Link to comment https://forums.phpfreaks.com/topic/123266-solved-multiple-values-into-1-database-table-spacing-it-out/ Share on other sites More sharing options...
lanmonkey Posted September 8, 2008 Share Posted September 8, 2008 I’m not sure what your trying to do here. From your description it sounds like your trying to store multiple variables into a single field in the database but your SQL query structure looks normal. You should have a separate column in your table for each bit of data you want to store, be it username, email, password, first name ect… What’s the structure of your database table? Link to comment https://forums.phpfreaks.com/topic/123266-solved-multiple-values-into-1-database-table-spacing-it-out/#findComment-636587 Share on other sites More sharing options...
obsidian Posted September 8, 2008 Share Posted September 8, 2008 First of all, with this type of data, you really should never enter it all into a single column like this. When you are using a relational database, you are much better off to use the DB as it is intended. You really should create a table with a column for each of the values you are wanting to store and then make the current column simply a reference to your new table. If, however, there are some odd constraints in the system requiring you to use this method, I would recommend just assigning all the values you need stored into an associative array and then serializing it to store as text in your database. This way, you don't have to worry about the different characters you may choose as a delimiter affecting your storage or retrieval. On the other side, all you have to do is retrieve the records and run unserialize on the data. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/123266-solved-multiple-values-into-1-database-table-spacing-it-out/#findComment-636590 Share on other sites More sharing options...
stublackett Posted September 8, 2008 Author Share Posted September 8, 2008 First of all, with this type of data, you really should never enter it all into a single column like this. When you are using a relational database, you are much better off to use the DB as it is intended. You really should create a table with a column for each of the values you are wanting to store and then make the current column simply a reference to your new table. If, however, there are some odd constraints in the system requiring you to use this method, I would recommend just assigning all the values you need stored into an associative array and then serializing it to store as text in your database. This way, you don't have to worry about the different characters you may choose as a delimiter affecting your storage or retrieval. On the other side, all you have to do is retrieve the records and run unserialize on the data. Hope this helps. Thanks for that... So I create X amount of columns to collate the small fragrments of information, Then I can obviously output it anyway using PHP (Spacing Line Breaks etc...) Link to comment https://forums.phpfreaks.com/topic/123266-solved-multiple-values-into-1-database-table-spacing-it-out/#findComment-636595 Share on other sites More sharing options...
obsidian Posted September 8, 2008 Share Posted September 8, 2008 Thanks for that... So I create X amount of columns to collate the small fragrments of information, Then I can obviously output it anyway using PHP (Spacing Line Breaks etc...) Exactly Link to comment https://forums.phpfreaks.com/topic/123266-solved-multiple-values-into-1-database-table-spacing-it-out/#findComment-636626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.