Forum Moderators: coopster

Message Too Old, No Replies

Stopping a record being inserted twice, if someone hits refresh

         

fintan

3:28 pm on Jul 6, 2004 (gmt 0)

10+ Year Member



How do I stop someone from submitting a record twice if they hit refresh. Can you do it in a 2 page layout instead of having a redirect page in between. Thanks

fintan.

WhosAWhata

4:19 pm on Jul 6, 2004 (gmt 0)

10+ Year Member



ok this is kind of a redirect, but if you say header("Location:page.php"); it will be fairly unnoticable

fintan

4:48 pm on Jul 6, 2004 (gmt 0)

10+ Year Member



What after its submited redirect to the same page. So would it look something like this

if (isset($_POST["submit"])) {
mysql_query($hdins);
header("Location: [localhost...]
}
elseif(!isset($_POST["submit"])){
return;
}
else{}

WhosAWhata

2:38 am on Jul 7, 2004 (gmt 0)

10+ Year Member



i don't quite follow you

fintan

9:20 am on Jul 7, 2004 (gmt 0)

10+ Year Member



This is what I was using to try the redirect without alot of success. I was trying to see if the varible was set and if it wasn't to do nothing.

hughie

10:27 am on Jul 7, 2004 (gmt 0)

10+ Year Member



you could set a session variable after the query has occured.

e.g.

<?php
if ($_SESSION['querydone']==1)
{
echo 'can't submit twice';
}
else
{
$sql=mysql_query("INSERT INTO ...");
$_SESSION['querydone']=1;
}
?>

ta,
hughie

charlier

10:36 am on Jul 7, 2004 (gmt 0)

10+ Year Member



If its the type of thing where they have to register and are given a 'member' type record you can just check if they have submitted the same request within the last x days and take whatever action you like. I do this on a literature request system (postal) and just ignore any request thats duplicated withing two weeks. If its > two weeks then I reprocess it and send a whats happening message to the people doing the mailings.

fintan

11:06 am on Jul 7, 2004 (gmt 0)

10+ Year Member



That works hughie but I've a session already done for when they login so they only see content persific to them. It runs the script and doesn't allow them to submit the query twice which is great but it doesn't display the rest of the page.

I thought of that already charlier but I've 15 to 20 users who will use the system all day so a time based system is kind of out the window.

hughie

12:17 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



That shouldn't interfere with any other session variables or stop anything else being displayed.

Not sure what the problem is there.

stick a code example up if your still having trouble.

ta,
hughie

fintan

3:43 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



Just fiddled with it a bit but it worked thanks.
One more thing I have a loggin page that's directed to that same page but if a user logs in another record is added. Any ideas

[edited by: fintan at 4:33 pm (utc) on July 7, 2004]

yowza

4:15 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



This is probably a stupid question, but I'll ask it any way. Is there a column that will always be unique? If so, create a "unique" index on that column.

hughie

5:09 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



not really with you there...

if you have 2 forms pointing at the same page make sure that the name of the submit button is different for each form then..
if (isset($_POST['submitA']))
{
form A sql...
}

if (isset($_POST['submitB']))
{
form B sql...
}

that what your after?

ta,
hughie

fintan

10:54 am on Jul 8, 2004 (gmt 0)

10+ Year Member



Yeah there is yowza its the usual auto increment, key field thing.

This is what I got so far. If someone logs in they insert a record which is what I'm trying to prevent now. While the insert is working fine and it's not submiting the record twice. I've basically three forms pointing at the same page. A login, insert and a update. So what am I missing?

if (isset($_POST['login']))
{
// Do nothing
}
if ($_SESSION['addcall']==1){
// Do nothing
}
else{
$sql=mysql_query($hdins);
$_SESSION['addcall']=1;
}
if ($_SESSION['update']==1){
// Do nothing
}
else{
$sql=mysql_query($hdupdt);
$_SESSION['update']=1;
}

hughie

5:34 pm on Jul 8, 2004 (gmt 0)

10+ Year Member



pretty dangerous else there

if ($_SESSION['addcall']==1){
// Do nothing
}
else{
$sql=mysql_query($hdins);
$_SESSION['addcall']=1;
}

i.e. it's going to run the SQL all the time unless addcall==1;

ta,
hughie

fintan

12:39 pm on Jul 13, 2004 (gmt 0)

10+ Year Member



How bout this then. If I do a select before hand then compare the select to the insert statement if they match do nothing else do the insert statement.