Page 1 of 1

INSERTing text containing commas into MySQL database

Posted: Sun Mar 28, 2004 9:25 am
by mjseaden
Dear All

For my new site, up until this point I have been using a MySQL database package to set up initial tables and insert test data, whilst developing the database 'reading' parts of the site.

However, I have now come across a problem - whilst I am able to use the MySQL syntax perfectly well, I am unable to insert text into the TEXT fields on the database table I am trying to write to, because it contains a comma and thus MySQL thinks that I am delimiting the fields rather than using English punctuation.

The 'comma' comes from text typed into a text area by the user, which I consequently want to write to the database.

Your help would be very much appreciated.

Many thanks

Mark

Posted: Sun Mar 28, 2004 9:29 am
by markl999
Can you paste the query you are using? Sounds like you arn't quoting values as commas have no special meaning in mysql strings.

Posted: Sun Mar 28, 2004 9:36 am
by mjseaden
This is a generic form:

Code: Select all

$query = 'INSERT INTO Datatable1 VALUES ('.$myid.', '.$_SESSION['Int_value1'].', '.$_SESSION['Int_value2'].', '.$_SESSION['text1'].', '.$_SESSION['text2'].', '.$_SESSION['float1'].', '.$_SESSION['text3'].', '.$_SESSION['text4'].', '.$_SESSION['int_value3'].', '.$_SESSION['int_value4'].', '.$_SESSION['int_value5'].')';
Regards

Mark

Posted: Sun Mar 28, 2004 9:39 am
by markl999
Yeah, you're not quoting the values. Try :

Code: Select all

$query = "INSERT INTO Datatable1 VALUES (
  '$propid',
  '{$_SESSION['Int_value1']}',
  '{$_SESSION['Int_value2']}',
  '{$_SESSION['text1']}',
  '{$_SESSION['text2']}',
  '{$_SESSION['float1']}',
  '{$_SESSION['text3']}',
  '{$_SESSION['text4']}',
  '{$_SESSION['int_value3']}',
  '{$_SESSION['int_value4']}',
  '{$_SESSION['int_value5']}')";

Posted: Sun Mar 28, 2004 10:04 am
by mjseaden
Hi mark
Your method seems to work, however only certain fields are being filled. It may be a problem with the $_SESSION variables so I'll have to check, but thanks for correcting the syntax.

Many thanks

Mark