473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Passing values from JavaScript into MySQL/PHP


First of all i know that PHP is a server side, and JavaScript is a Client
side programming language, but i need to know if there is any way i can add
the variable "countDownInterval" from this particular FULL code into a MySQL

Here's the drill:

I have a timer on a PHP webpage, and i want to prevent the user from doing a
refresh to reset the timer to it's full time (in this case 100), and i
though of since i can pass the variable from PHP into JavaScript i could
save the timer into a MySQL field and each time the user refreshs the page
it's fethed from MySQL and passed by PHP back into JavaScript.

So it user has only 5 seconds left, and uses a refresh, the script fetchs
the value 5 from MySQL table and continues to count down from there.

Is this possible? Let's me refrase that i only need a way to pass a variable
from this JavaScript into MySQL, and that the page cannot be refreshed by
it's own, since it has some pictures and it takes some time to load. the
timer is on a <ilayer>

HERE'S my example code, that shows how to pass values from PHP into
JavaScript, please complete it in a way i can pass variable
"countDownInterval" back into MySQL.

************************************************** **************************


<script language="JavaScript">
//configure refresh interval (in seconds)
var countDownInterval=<?php echo $somePhpVariable ?>; // THIS IS WHERE
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200

<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2"
width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>


var countDownTime=countDownInterval+1;
function countDown(){
if (countDownTime <=0){
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML =countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_reload.document.c_reload2.document.writ e('Next <a
href="javascript:window.location.reload()">refresh </a> in <b
id="countDownText">'+countDownTime+' </b> seconds')
document.c_reload.document.c_reload2.document.clos e()
counter=setTimeout("countDown()", 1000);

function startit(){
if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
document.write('Next <a
href="javascript:window.location.reload()">refresh </a> in <b
id="countDownText">'+countDownTime+' </b> seconds')

if (document.all||document.getElementById)

Jul 23 '05 #1
2 5006
RootShell wrote:

First of all i know that PHP is a server side, and JavaScript is a
Client side programming language, but i need to know if there is any
way i can add the variable "countDownInterval" from this particular
FULL code into a MySQL field.


AFAIK there are no Javascript functions that allow for MySQL interaction.
That aside, storing the value in the database seems an inefficient solution.

Have you tried putting the countdown variable into a cookie? Such a
procedure could be:
onload {
get countdown from cookie
if countdown is set
resume countdown
begin new countdown

When the user clicks the reload link, you could call a function that puts
the current countdown value into the cookie.

Hope that helps.


Jason, aka The Blue Raja
Jul 23 '05 #2
JRS: In article <41**********************@news.telepac.pt>, dated Mon,
26 Jul 2004 01:45:45, seen in news:comp.lang.javascript, RootShell
<AN***************@Netcabo.ptANTISPAM> posted :
counter=setTimeout("countDown()", 1000);

That will not count seconds accurately.

See current thread "Countdown timer inaccurate - losing time!?!" in
c.l.j, and the FAQ, via below.

Is a.c.l.j generally considered valid? I think Demon does not carry it.

John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Raju V.K | last post by:
I am developing a web site which requires a set og unique values be transferred between pages and server many times. There fore i decided to put the values in an array so that only one reference to...
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
by: LeTubs | last post by:
Hi I'm think I'm having some problem with pointers..... namely passing them around...Or I think ? I've used gdb to find the following (note conn is of type MYSQL *conn). Program received...
by: Peter | last post by:
Hello I have the following tag <select name="cat" id="cat" onchange="popUpWin('cmPhaseReload.php?category='+document.getElementById('cat').options.value ,600,600,'yes')" class="tbl_result"...
by: Geoff Cox | last post by:
Hello, The code below is aimed at passing the date in the yyyyMMdd format from the javascript calendar in an html file to the php in a another file which then searches a MySQL database. For...
by: satish2112 | last post by:
Hi, I have a text-area which contains values from mysql database and 2 buttons, Edit and Update. When I click on the Edit button, I can edit the text-area (initially non-editable). After this,...
by: Lazandra | last post by:
Hiya I have an order form and once submitted it goes straight to the payment form. I have 2 databases one order and the other payment. So in the order form i need to pass the id to the payment...
by: Joshepmichel | last post by:
Please to help me to following problem I want to do this 1. create Table Name MEMBER on the Database Name "mytestdb", 2. Add the Values to the Table through the Key board Inputs during running...
by: adamace5o | last post by:
When i try to use post variables with php and mysql i can't get the insert into statement to accept varibles as values. If i use 'test' instead of $test it does work. I suspect it is something to do...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.