473,396 Members | 1,847 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,396 software developers and data experts.

Passing values from JavaScript into MySQL/PHP

Hello

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.

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.

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

<?PHP
$somePhpVariable=100;
?>

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

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

<script>

var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.reload()
return
}
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')
countDown()
}

if (document.all||document.getElementById)
startit()
else
window.onload=startit

</script>
Jul 23 '05 #1
2 5007
RootShell wrote:
Hello

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.


<snip>

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
else
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

5
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...
3
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) {...
2
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...
2
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"...
2
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...
1
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,...
5
Lazandra
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...
3
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
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...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.