Unix Technical Forum

double insert

This is a discussion on double insert within the MySQL forums, part of the Database Server Software category; --> Hello, I use php/mysql for several years, and there, an error without explanation. The PHP script below inserts an ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:27 AM
Almaleh
 
Posts: n/a
Default 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)


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:27 AM
Jerry Stuckle
 
Posts: n/a
Default 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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:27 AM
Almaleh
 
Posts: n/a
Default 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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:27 AM
J.O. Aho
 
Posts: n/a
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:27 AM
Jerry Stuckle
 
Posts: n/a
Default 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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:27 AM
aaooo54
 
Posts: n/a
Default 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.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 11:28 AM
Almaleh
 
Posts: n/a
Default 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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 11:28 AM
Almaleh
 
Posts: n/a
Default 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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 11:28 AM
Jerry Stuckle
 
Posts: n/a
Default 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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 11:28 AM
Almaleh
 
Posts: n/a
Default 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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:02 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com