PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > double insert
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
double insert

Réponse
 
LinkBack Outils de la discussion
Vieux 23/09/2007, 19h57   #1
Almaleh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut double insert

Hello,

I use php/mysql for several years, and there, an error without
explanation.

The PHP script below inserts an record two times, the same two times.
Why ? Any idea ?

Thank you
Francois


include ('connecte.csv');
$link = mysql_connect($sql,$user,$pwd) or die("ERROR");
mysql_select_db($db,$link);
mysql_query("insert into listescouts (categorie,nom) values
('test','essai')",$link);
mysql_close($link);

With another table, no problem. Both tables were built in the same time
(different fields of course)


  Réponse avec citation
Vieux 23/09/2007, 20h09   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

Almaleh wrote:
> Hello,
>
> I use php/mysql for several years, and there, an error without explanation.
>
> The PHP script below inserts an record two times, the same two times.
> Why ? Any idea ?
>
> Thank you
> Francois
>
>
> include ('connecte.csv');
> $link = mysql_connect($sql,$user,$pwd) or die("ERROR");
> mysql_select_db($db,$link);
> mysql_query("insert into listescouts (categorie,nom) values
> ('test','essai')",$link);
> mysql_close($link);
>
> With another table, no problem. Both tables were built in the same time
> (different fields of course)
>
>


It won't, unless you're calling the script twice.

Echo a message every time you execute it and see what you get.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Vieux 23/09/2007, 20h24   #3
Almaleh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

> It won't, unless you're calling the script twice.
Only one time, I'm sure.

> Echo a message every time you execute it and see what you get.

Nothing, the script is simple and without problem in its syntax

"Insert into"... inserted in phpmyadmin is ok : only one record
inserted, but with the previous php script, it's bad (although with
another table, it's ok)

Francois


  Réponse avec citation
Vieux 23/09/2007, 21h46   #4
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

Almaleh wrote:
> I use php/mysql for several years, and there, an error without explanation.
> The PHP script below inserts an record two times, the same two times.
> Why ? Any idea ?
> include ('connecte.csv');
> $link = mysql_connect($sql,$user,$pwd) or die("ERROR");
> mysql_select_db($db,$link);
> mysql_query("insert into listescouts (categorie,nom) values
> ('test','essai')",$link);
> mysql_close($link);



The script most likely is called twice.

--

//Aho
  Réponse avec citation
Vieux 23/09/2007, 22h06   #5
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

Almaleh wrote:
>> It won't, unless you're calling the script twice.

> Only one time, I'm sure.
>
>> Echo a message every time you execute it and see what you get.

> Nothing, the script is simple and without problem in its syntax
>
> "Insert into"... inserted in phpmyadmin is ok : only one record
> inserted, but with the previous php script, it's bad (although with
> another table, it's ok)
>
> Francois
>
>


The code you posted will only insert twice if you call it twice.

Try putting the following in your code:

echo "I'm inserting a new record now<br>\n";

And see if you don't get two messages.

Either that or you're inserting in another place, also. Comment out the
mysql_query statement and see if it's getting inserted at all.

One or the other is happening.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Vieux 24/09/2007, 09h51   #6
aaooo54
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

> The PHP script below inserts an record two times, the same two times.
> Why ? Any idea ?
> mysql_query("insert into listescouts (categorie,nom) values
> ('test','essai')",$link);


add timestamp to your query, you will be able to compare time of inserted
values.
if script is called two times it will be visible as two diffirent
timestamps.
regards,
R.


  Réponse avec citation
Vieux 26/09/2007, 20h58   #7
Almaleh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

Après mûre réflexion, J.O. Aho a écrit :
> Almaleh wrote:
>> I use php/mysql for several years, and there, an error without explanation.
>> The PHP script below inserts an record two times, the same two times.
>> Why ? Any idea ?
>> include ('connecte.csv');
>> $link = mysql_connect($sql,$user,$pwd) or die("ERROR");
>> mysql_select_db($db,$link);
>> mysql_query("insert into listescouts (categorie,nom) values
>> ('test','essai')",$link);
>> mysql_close($link);

>
>
> The script most likely is called twice.

I don't think so because there is only a mysql_query instruction. What
do you think ,
Thanks
Francois


  Réponse avec citation
Vieux 26/09/2007, 21h25   #8
Almaleh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

aaooo54 a émis l'idée suivante :
>> The PHP script below inserts an record two times, the same two times.
>> Why ? Any idea ?
>> mysql_query("insert into listescouts (categorie,nom) values
>> ('test','essai')",$link);

>
> add timestamp to your query, you will be able to compare time of inserted
> values.
> if script is called two times it will be visible as two diffirent timestamps.
> regards,
> R.


thanks but the result is not very significant because it's measured in
second not in milliseconds
Francois


  Réponse avec citation
Vieux 26/09/2007, 21h31   #9
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

Almaleh wrote:
> Après mûre réflexion, J.O. Aho a écrit :
>> Almaleh wrote:
>>> I use php/mysql for several years, and there, an error without
>>> explanation.
>>> The PHP script below inserts an record two times, the same two times.
>>> Why ? Any idea ?
>>> include ('connecte.csv');
>>> $link = mysql_connect($sql,$user,$pwd) or die("ERROR");
>>> mysql_select_db($db,$link);
>>> mysql_query("insert into listescouts (categorie,nom) values
>>> ('test','essai')",$link);
>>> mysql_close($link);

>>
>>
>> The script most likely is called twice.

> I don't think so because there is only a mysql_query instruction. What
> do you think ,
> Thanks
> Francois
>
>


So? Why can't it be called twice?

The fact something is being inserted twice means you are performing two
inserts statements.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Vieux 26/09/2007, 22h02   #10
Almaleh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

>
> So? Why can't it be called twice?
>
> The fact something is being inserted twice means you are performing two
> inserts statements.

I inserted echo $query; in the php script just above
mysql_query($query,$link); and it performs only one time because there
is only one mysql_query instruction.

All my php scripts are written like this for several years, and now a
unsolved problem.

Francois


  Réponse avec citation
Vieux 26/09/2007, 22h14   #11
Almaleh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double insert

>
> So? Why can't it be called twice?
>
> The fact something is being inserted twice means you are performing two
> inserts statements.


My problem is solved without solution. I explain : I wrote the script
in another text editor (using only ctrl-c/v), and now, it runs without
error.
Why, I don't know

Francois


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h35.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14873 seconds with 19 queries