Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem of insertion




11:06 pm on Sep 4, 2002 (gmt 0)

10+ Year Member

I 've made a php script that aimt to insert datas from a form into a mysql data base.
I want to insert a first group of information in atable with an auto_increment id.Then i shoul have the id of the last insertion with the command :mysql_insert_id().
The probleme is that it works very nice the first time (when i try) and the second time it doesn' t work.In fact the second query(requete2 in the code) doesn't work and it stop the code.I cant find the bug ,i need help.
This my code

//connect() is a personnal function that i sue to set the connection
//with the pass,the login...

$requete="INSERT INTO site (nom,description,url,k,idcat,idscat) VALUES ('$nom','$description','$url','$k','$idcat','$idscat')";
$resultat=mysql_query($requete,$co) or die("impossible réaliser reqete1");
$requete2="INSERT INTO editeur (idsite,adresse,ville,pays,tel,code,fax,email) VALUES ('$idsite1','$adresse','$ville','$pays','$tel','$code','$fax','$email')";
$resultat2=mysql_query($requete2,$co) or die("impossible de réaliser requete2.");
$requete3="SELECT email FROM editeur WHERE idediteur='$idediteur1'";
while ($adr=mysql_fetch_array($resultat3)){

$sujet="Confirmation du referencement de $nom au service de mon compagnie";
$corps="Cher éditeur du site $nom,\n\nLe service de mon compagnie à le plaisir de vous annoncez que votre site , $url , a bien été référencé dans notre base de donnée.\nVous pouvez visiter notre site à l' adresse:\nhttp://www.monsite.com.\n\nPour toute réclamation ou requète veuillez nous contacter à l' adresse suivante:addresse@monsite.com.\nMerci.";
$lettre1=mail($dest,$sujet,$corps) or die ("impossible d' envoyer la lettre d' inscription à $nom");
if($lettre1){echo"mission accomplie!";}

[edited by: jatar_k at 11:50 pm (utc) on Sep. 4, 2002]


11:53 pm on Sep 4, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

What´s the error message when your script stops? On which line does the error occur?


11:55 pm on Sep 4, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Bienvenue a WebmasterWorld masterjr,
I removed the specific references (urls and email addresses) from your post.

check to see if $idediteur1 == 0;

The reason from php.net on mysql_insert_id() [php.net]
"mysql_insert_id() returns 0 if the previous query does not generate an AUTO_INCREMENT value."

another possibilty

"If your AUTO_INCREMENT column has a column type of BIGINT, the value returned by mysql_insert_id() will be incorrect. Instead, use the internal MySQL SQL function LAST_INSERT_ID() in an SQL query."


Featured Threads

Hot Threads This Week

Hot Threads This Month