vandergeek
Technical User
I have a table in a postgre database that has several fields that are text arrays. I'm using php to take the data submitted by a form to insert it. This is the php code I'm using to escape my variables:
And this is the sql insert I am using:
The database is running on a *nix server - I'm not sure what though, and that is the only query that is allowing me to insert my variables into the text array field (field3 in the example above).
I have a local setup on a windows xp box that lets me insert each of the variables "var1", "var2" etc. into the text array field (field3) through a query like so:
This doesn't work on the *nix server where the site is hosted.
The problem I am having on the *nix server is that if a textarea has some thing like:
as the input, it is inserting it into the database, but it is not escaping the inverted commas with a slash so then when the text is pulled from the database, the inverted commas are not shown. It doesn't do this on my local install on XP.
Can anyone please help me with this? I can't figure out how to put the variables into the postgre text array whilst keeping the inverted commas in any text input escaped.
Thanks in advance.
Code:
function escapeData($var) {
$var = stripslashes($var);
$var = strip_tags($var);
$var = pg_escape_string($var);
return $var;
}
And this is the sql insert I am using:
Code:
INSERT INTO table(field1, field2, field3, field4) VALUES ('$field1', '$field2', '{\"$val1\", \"$val2\", \"$val3\", \"$val4\"}', '$field4')
The database is running on a *nix server - I'm not sure what though, and that is the only query that is allowing me to insert my variables into the text array field (field3 in the example above).
I have a local setup on a windows xp box that lets me insert each of the variables "var1", "var2" etc. into the text array field (field3) through a query like so:
Code:
INSERT INTO table(field1, field2, field3[1], field3[2], field3[3], field3[4], field4) VALUES ('$field1', '$field2', '$val1', '$val2', '$val3', '$val4', '$field4')
This doesn't work on the *nix server where the site is hosted.
The problem I am having on the *nix server is that if a textarea has some thing like:
Code:
...this is a "quote" by me...
as the input, it is inserting it into the database, but it is not escaping the inverted commas with a slash so then when the text is pulled from the database, the inverted commas are not shown. It doesn't do this on my local install on XP.
Can anyone please help me with this? I can't figure out how to put the variables into the postgre text array whilst keeping the inverted commas in any text input escaped.
Thanks in advance.