Jump to content

[SOLVED] Multiple Values into 1 Database Table - Spacing it out


stublackett

Recommended Posts

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

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

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

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