Page 1 of 1

One INSERT generates two records

Posted: Tue Aug 17, 2004 1:56 pm
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

Posted: Tue Aug 17, 2004 2:46 pm
by lostboy
The problem code is not here. My guess is that somewhere in the calling page, the code is included or called 2x

Just a simple form

Posted: Thu Aug 19, 2004 2:11 pm
by epg
The calling page just contains a form:

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



?????

Posted: Thu Aug 19, 2004 2:30 pm
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?

Posted: Wed Aug 25, 2004 2:31 pm
by epg
I see it just once. And no, it is not inside any loop

Posted: Wed Aug 25, 2004 2:50 pm
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?