Forum Moderators: coopster

Message Too Old, No Replies

Yet another query prob - tied to forms

mysql query, php, forms, line end return

         

Minuteman

10:47 pm on Apr 18, 2007 (gmt 0)

10+ Year Member



I'm using a form text area to collect comma separated values to submit to the db.

If I list the values one after another in one line, as in value1,value2,value3 etc, everything works fine but I would like to be able to simply list the values one under the other, as in -

value1,
value2,
value3
etc.

When I try that, it inserts a hidden return line end code in the data. This shows up in the db, totally messing up the plan. How can I screen out the line end/return code from the query? Here is the query code -

$query = 'INSERT INTO '
.$settings['categories_table']
.'(`name`,`parent`) VALUES ("'
.$pieces[$key]
.'","'
.$_GET['bulk_upload_id']
.'")'
;
the url for the first example looks like this
name=istexample%2Cistexample2%2Cistexample3&bulk_upload_id=111

the url for the second example looks like this
?name=atest1%2C%0D%0Aatest2%2C%0D%0Aatest3&bulk_upload_id=111

but the endline code "%0D%0" isn't being shown in the echo of the query statement when it runs?
here is the echo -
INSERT INTO categories(`name`,`parent`) VALUES ("test2","111")

Thanks

cameraman

11:05 pm on Apr 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use str_replace() [php.net] to yank the \n out. I'm not exactly seeing where you're referring to the form value - my guess is you're doing something to it and putting it into an array called $pieces?
At any rate, you could do something like this:
$_GET['name'] = str_replace("\n",'',$_GET['name']);