I've got this:
foreach($_POST['pos'] as $value) {
$new_value = "UPDATE users SET regnr='" . $value . "'
WHERE username='" . mysql_real_escape_string($_COOKIE['username']) . "'";
}
// Connect to database
$opendb = mysql_connect($dbhost, $dbuser, $dbpass) or die("Kunde inte ansluta till MySQL:<br>" . mysql_error());
mysql_select_db($dbname) or die("Kunde inte ansluta till databasen:<br>" . mysql_error());
mysql_query($new_value) or die(mysql_error());
// Close database
mysql_close($opendb);
Information:
$_POST['pos'] holds a value from the database in a hidden input. This value I have choosen to split with str_split($r['regnr'], 6); into a JQuery sortable list. If I type echo $value; in the foreach loop I've got the new value (not splitted, as I want) from the JQuery sortable list. I need all values from the list, and I get it with echo. But if I use $value variable to UPDATE the database that it came from, it just updates with the last value from the JQuery sortable list.
Can someone solve that? :D
username, then a user could inject this valueyou-got-hacked'; DROP DATABASE;and poof no more database. Yes that's how serious SQL injection can get. Use the PDO library or the MySQLi library.