I have this script:
foreach ($_GET[selected] as &$value) {
echo "$value|";
mysql_query("UPDATE ordre SET enheder='$row3[enheder]|$value' WHERE id='1'") or die(mysql_error());
}
It doesn't do what I want to. I want it to add the strings from array $value to rest thats already in MySql.
If
$value = "Server1|Server2|Server3|";
Then it should update "enheder" to "OLD TEXT|Server1|Server2|Server3|" but it doesn't?
It would be better to build the string you want to add in php, then use MySQL's CONCAT()
function to add this one string to the value already in the database. Also, as you are creating your sql from user input, escaping this input is also essential.
One way you could do the above is:
<?php
$values = mysql_real_escape_string(implode("|", $_GET['selected'])) ;
$sql = "
UPDATE ordre
SET enheder = CONCAT(enheder, '|', '{$values}')
WHERE id = '1'
" ;
mysql_query($sql) ;
?>