1

I have a variable that holds multiple data, and I want to insert this multiple data into PostgreSQL database using a single query.

the field on my table is this: stud_tbl(id,fname,lname)

and this is the variable that holds multiple data;

variable = (123,ron,lum),(234,nald,bay),(345,rol,lumz)

my query:

str = "insert into stud_tbl values ('" & variable & "')"

when I execute my query their was an error and I can't identify the error.

Patrick
  • 29,357
  • 6
  • 62
  • 90
rolz
  • 69
  • 1
  • 12
  • You quote the entire variable. Instead you should only quote the text values inside the variable. – Patrick Oct 15 '15 at 03:03
  • how to quote the value inside the variable sir? – rolz Oct 15 '15 at 03:18
  • Which Programming language you're using ? – Vivek S. Oct 15 '15 at 04:28
  • the scenario goes like this,, i select that data into different table, concat all selected data and pass to a variable "variable" thats why the data is like ths (123,ron,lum),(234,nald,bay),(345,rol,lumz), so my problem is cant save those data into table "stud_tbl" with a single query – rolz Oct 15 '15 at 06:11

2 Answers2

1

To expand on @Patrick's comment:

variable = "(123,'ron','lum'),(234,'nald','bay'),(345,'rol','lumz')"

the query:

str = "insert into stud_tbl values " & variable 

Though the usual warnings (How can I prevent SQL injection in PHP?) about this not being best practice apply.

Community
  • 1
  • 1
Turophile
  • 3,367
  • 1
  • 13
  • 21
-1

Value of your variable should be enclosed with quotation marks

variable = "(123,ron,lum),(234,nald,bay),(345,rol,lumz)"
Nadz
  • 15
  • 5