Invio
1
Hi,
Have just encountered a problem which I just can’t seem to figure out in my ability.
I have a text area that tracks the x and y position of dragged items, it logs each drop event as:
id,xposition,yposition
So when submitted you end up with something similar too (but longer):
353,563,76
356,231,43
357,348,134
I need to explode each line out and then explode each line to give me the id, x position and y position so I can update these results in the database.
Any help in achieving this will be greatly appreciated.
Thanks!
Mandes
2
This should get you started
<?php
$input = $_POST['input'];
$lines = explode("\
", $input);
foreach ($lines as $row){
$values = explode(",", $row);
echo 'x=' . $values[0] . ' ' ;
echo 'y=' . $values[1] . ' ' ;
echo 'z=' . $values[2] . '<br />';
}
?>
<form action="" method="post">
<textarea name="input">
353,563,76
356,231,43
357,348,134</textarea>
<input type="submit" >
</form>
Invio
3
Thanks for this!
I’m trying to put those values into variables, how can I achieve this?
I need to have $id $xposition and $yposition
Thanks 
Mandes
4
.......
$id = $values[0];
$xposition = $values[1];
$yposition = $values[2];
.......
Invio
5
I did just that myself, but when I try to enter them into an SQL query and echo them it just doesn’t happen?..
echo"Saved! $id $xposition $yposition";
Mandes
6
Cant tell without seeing your code
Invio
7
$id = $values[0];
$xposition = $values[1];
$yposition = $values[2];
$update = mysql_query("UPDATE `outfit_items` SET `positionx` = '$xposition', `positiony` = '$yposition' WHERE `id` = '$id' AND `owner` = '$user[id]'");
echo"Saved! $id $xposition $yposition";
Mandes
8
but where is that in relation to my code ?
Invio
9
$data= $_POST['data'];
$lines = explode("\
", $data);
foreach ($lines as $row){
$values = explode(",", $row);
$id = $values[0];
$xposition = $values[1];
$yposition = $values[2];
$update = mysql_query("UPDATE `outfit_items` SET `positionx` = '$xposition', `positiony` = '$yposition' WHERE `id` = '$id' AND `owner` = '$logged[id]'");
echo"Saved! $id $xposition $yposition";
}
instead of echo"Saved! $id $xposition $yposition";
try this echo “Saved!”.$id.“,”.$xposition.“,”.$yposition;
$data= $_POST[‘data’];
$lines = explode("
", $data);
foreach ($lines as $row){
$values = explode(“,”, $row);
$id = $values[0];
$xposition = $values[1];
$yposition = $values[2];
$update = mysql_query(“UPDATE outfit_items
SET positionx
= ‘$xposition’, positiony
= ‘$yposition’ WHERE id
= ‘$id’ AND owner
= ‘$logged[id]’”);
echo"Saved! $id $xposition $yposition";
}
Mandes
11
invio
Your code is fine if your not getting any results its because $_POST[‘data’] doesnt contain any data to parse.
Invio
12
Am I missing something?..
echo"</div>
<div class=\\"panel\\">
<form action=\\"savedragdrop.php\\" method=\\"POST\\">
<textarea id=\\"data\\" style=\\"width:50px; height:100px; margin-top:280px\\" wrap=\\"off\\"></textarea>
<input type=\\"submit\\" value=\\"Save\\">
</form></div>
</body></html>";
Mandes
13
your textarea doesnt have a name property
Invio
14
Ah sorry, haven’t done this in quite a while! Thanks for your help 