Jump to content

saving to database after few seconds

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
iory

iory

    Newbie

  • Members
  • Pip
  • 3 posts
dear all, im newbie here :p
I have this code, after user make a selection, he/she see the data that he/she selected, then, that data name will be automatically save into their record database.

is it possible to make that, the record will be saved after user see for few seconds (ex: 5 seconds). so that it wont save immediately ( for consideration that, if user see the data for more than 5 seconds, that
means he/she is interested, then it should be saved automatically)


<?php

if ($registration>0){

 $qry="SELECT * FROM registration WHERE id_registration=".$registration" LIMIT 1";

 $exe=mysql_query($qry);

 $show=mysql_fetch_array($exe);

 if (mysql_num_rows($exe)==1){

 echo "<div class='divide'>  ++ ".$show['title_registration']." ++</div><br />";

  

$qry="INSERT INTO tb_history VALUES('',".$_SESSION['ID'].",'".$show['name_word']."',

'".$_SERVER[HTTP_REFERER]."','".date("Y-n-j H:i:s")."')";

?>


can someone please help me with this? :(

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
No, since PHP is a server side language it processes all instructions before presenting it to the user. This means you can't have a "wait" of 5 seconds before saving using the script above. You can, however, display the data and use JavaScript timer to count down 5 seconds. Once the JavaScript timer reaches 5 seconds you could use AJAX to connect to another PHP script that runs your insert command above.

#3
iory

iory

    Newbie

  • Members
  • Pip
  • 3 posts
so, that means, i cannot put the script all together in one PHP file and make a "wait" of 5 seconds before saving to database? i never thought about that before, im newbie in PHP :(...thx admin for clearing this out :)

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
That is right. You can put the insert into a secondary script and use AJAX like I stated though. If you are a newbie this may be a little advanced. Why do you want to wait 5 seconds anyway?

#5
iory

iory

    Newbie

  • Members
  • Pip
  • 3 posts
yes, i think this is really advanced for me..the reason why i want it to wait 5 seconds before saving into the database is because, the result of this script will be [title_registration] <- it is a data name, so im thinking, if user checked the "data name", i want it to be save into user record history, for later use. Maybe next time user check his record, he can see that he checked this "data" before. But user maybe just clicking without paying attention to this data name.

Thats why, i want it to be saved after few seconds, for considerations that, if user really interested about that "data", he should at least see and checked for few seconds. :)