One INSERT generates two records

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
epg
Forum Newbie
Posts: 3
Joined: Tue Aug 17, 2004 1:56 pm

One INSERT generates two records

Post by epg »

I have these instructions

Code: Select all

<?php
$link = mysql_connect() or die("Unavailable connection : " . mysql_error());
mysql_select_db("cart") or die("Unavailable BD.");
mysql_query ("insert into tintas(tin_name) values ('Magenta')" , $link);
echo "Record inserted";
mysql_close ($link);
?>
The issue is that if I load these page directly in the browser it works fine, inserts one record. But if this page loads from a link of another page, it inserts two records. In fact, the tests I have performed, it executes twice (I know this because I've tried to insert data as a result of an operation and the records inserted are consistent with the operation)

Please Help
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

The problem code is not here. My guess is that somewhere in the calling page, the code is included or called 2x
epg
Forum Newbie
Posts: 3
Joined: Tue Aug 17, 2004 1:56 pm

Just a simple form

Post by epg »

The calling page just contains a form:

<form method="post" action "page2.php">
<input type="text" value="">
<input type="submit">
</form>



?????
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

So you're saying when you post this form you see "Record inserted" displayed twice too ?
What else does page2.php contain? Is the insert query inside any form of loop or condition?
epg
Forum Newbie
Posts: 3
Joined: Tue Aug 17, 2004 1:56 pm

Post by epg »

I see it just once. And no, it is not inside any loop
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

are you including the page twice in the calling page? Within and outside of a function maybe...can you post all the code?
Post Reply