update fields problem

admin

Administrator
Staff member
I have four rows in a form. Each row consist of a couple of fields. I would like to find a correct way to update these fields. I have a loop that goes through each row. From 0 to 3. When the page is loaded it collect values (sent from another page) from a database.Sometimes just one row is filled in, sometimes 4,3 or two rows. I want to set if the first field is empty it will delete the row. If its filled it will update, unless there isn't a value sent from the browser it will insert. In other words, I want it to insert a row if it doesnt exist from before. Else update, unless the field is empty then delete. Something goes wrong, heres the code;

// if someone presses update
if ($uppdatera) {

// explode the string $idnummer which consists of primary keys like 5235, 5236 and so on
$idnummer=explode (",",$ids);

for ($i=0; $i<=3; $i++)
{
if (!$kronor[$i]=="" && $idnummer[$i])
{
// $kronor is the first field

$sql= "DELETE FROM likvid WHERE ID='$idnummer[$i]'";
$result = mysql_query($sql,$db);
continue;
} else
if ($idnummer[$i] && $kronor[$i]!=="")
{
$sql = "UPDATE likvid SET DEPOT='$depot', BOKARE='$anvcookie', NAMN='$namn', DATUM='$olddate', BANK='$bank[$i]', KRONOR='$kronor[$i]', KONTO='$konto[$i]', TELEFON='$ring[$i]', KOMMENTAR='$kommentar[$i]', KONTROLL='TOM', KONTROLLDATUM='TOM' WHERE ID='$idnummer[$i]'";
$result = mysql_query($sql,$db);
continue;
}
if (!$idnummer[$i] && !$kronor[$i]=="")
{
$sql = "INSERT INTO likvid (bokare, depot, namn, kronor, bank, konto, kommentar, telefon, datum) VALUES ('$anvcookie','$depot','$namn','$kronor[$i]','$bank[$i]','$konto[$i]','$kommentar[$i]','$ring[$i]','$olddate')";
$result = mysql_query($sql,$db);
continue;
}

}
 
Back
Top