homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Problem of insertion

10+ Year Member

Msg#: 1176 posted 11:06 pm on Sep 4, 2002 (gmt 0)

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]



WebmasterWorld Senior Member 10+ Year Member

Msg#: 1176 posted 11:53 pm on Sep 4, 2002 (gmt 0)

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


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

Msg#: 1176 posted 11:55 pm on Sep 4, 2002 (gmt 0)

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."

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved