MySQL Forums
Forum List  »  PHP

Double insert into mysql db
Posted by: scantagalli
Date: April 29, 2005 03:26AM

hi
I have a problem with insert record into mysql db.
When i save a record into db, this is saved two times. This is not correct!!

<?

if (!empty($_GET['IDA']))
{
$indice=$_GET['IDA'];
}
else
{
$indice="";
}

if ($indice=="")
{
$attivita= new attivita("Nuovo",$indice1);
}
else
{
$attivita= new attivita($indice,$indice1);
}


$attivita->tipologia=$_POST['tipologia'];
$attivita->nota=$_POST['note'];

$attivita->Data=convertiData($_POST['date1xx']);
$attivita->Ora =$_POST['ora'].":".$_POST['minuti'];
$attivita->scadenza=$_POST['idsca'];
$idattivita=$attivita->salva_attivita($indice);

echo "<script language='Javascript'>top.visibile.location.href='$indirizzo';</script>";

?>

function salva_attivita() {
$connessione = & connetti_database();


mysql_query("LOCK TABLE Attività WRITE") or die("Query non valida: " . mysql_error());

if ($this -> id == "Nuovo") {
$query = "REPLACE INTO Attività(pratica, scadenza, Tipologiattivita, Note, idutentecreatore, datacreazione, idutentemodifica, dataultimamodifica, Data, Ora) VALUES (" . $this->pratica . ", NULL, " . $this->tipologia . ", '" . $this->nota . "'," . $this->idutentecreatore . ",'". $this->datacreazione ."',". $this->idutentemodifica .",'" . $this->dataultimamodifica."','". $this->Data ."','".$this->Ora."')";

mysql_query($query) or die("Query non valida inserimento attività: " . mysql_error());

$query2="SELECT * FROM Attività WHERE ID=LAST_INSERT_ID();";
$row = mysql_fetch_row(mysql_query($query2));
$id_insert = $row[0];

} else {
$query = "UPDATE Attività SET note= '" . $this->nota . "', Tipologiattivita= " . $this->tipologia . ", idutentemodifica=" . $this->idutentemodifica . ", dataultimamodifica='". $this->dataultimamodifica . "', Data='". $this->Data."', Ora='". $this->Ora . "', Scadenza=NULL WHERE id=" . $this->id;

mysql_query($query) or die("Query aggiornamento attività non valida: " . mysql_error());


mysql_query("UNLOCK TABLES");

mysql_close($connessione);

return $id_insert;


}

I am 100% sure (and I really mean 100%) that my script is ok.
I don't execute the query twice or my script isn't run twice.

Help me please
(mysql version 4.1)
(php version 5.0)

Options: ReplyQuote


Subject
Written By
Posted
Double insert into mysql db
April 29, 2005 03:26AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.