473,756 Members | 4,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "countDownInter val" 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
"countDownInter val" back into MySQL.

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

<?PHP
$somePhpVariabl e=100;
?>

<script language="JavaS cript">
//configure refresh interval (in seconds)
var countDownInterv al=<?php echo $somePhpVariabl e ?>; // THIS IS WHERE
I PASS THE PHP VARIABLE TO JAVASCRIPT
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=2 00
</script>

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

<script>

var countDownTime=c ountDownInterva l+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=c ountDownInterva l;
clearTimeout(co unter)
window.location .reload()
return
}
if (document.all) //if IE 4+
document.all.co untDownText.inn erText = countDownTime+" ";
else if (document.getEl ementById) //else if NS6+
document.getEle mentById("count DownText").inne rHTML=countDown Time+" "
else if (document.layer s){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_relo ad.document.c_r eload2.document .write('Next <a
href="javascrip t:window.locati on.reload()">re fresh</a> in <b
id="countDownTe xt">'+countDown Time+' </b> seconds')
document.c_relo ad.document.c_r eload2.document .close()
}
counter=setTime out("countDown( )", 1000);
}

function startit(){
if (document.all|| document.getEle mentById) //CHANGE TEXT BELOW TO YOUR OWN
document.write( 'Next <a
href="javascrip t:window.locati on.reload()">re fresh</a> in <b
id="countDownTe xt">'+countDown Time+' </b> seconds')
countDown()
}

if (document.all|| document.getEle mentById)
startit()
else
window.onload=s tartit

</script>
Jul 23 '05 #1
2 5060
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 "countDownInter val" 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.ptA NTISPAM> posted :
counter=setTim eout("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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
7613
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 the array is needed ratherthan idividual reference. The situation is like this: When the page is loaded based on the user input say 6 values are created like character1="tom", character2="jerry", Character3="micky", Character4="donald",...
3
14946
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
1550
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 signal SIGSEGV, Segmentation fault. 0x804a53e in get_next_chunk (conn=Error accessing memory address 0xbf000a38: Bad address. ) at fmysql.c:315
2
2918
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" size="1"> the cat field is a drop down list
2
5882
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 some reason the sendPhp is not working. I need to send
1
3306
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, if I click on the Update button, the values in the text-area must be updated in the mysql database. I am storing the values of the text-area in a variable. I am using javascript to pass the variable.
5
1710
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 form to tie them together. Heres my code... can anyone help? Cheers xx
3
7702
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 the My Java Application.; Therefore I used this following codes, It Consists the seperate parts for the Raede and Member Class for the purposely I craetes. 3. I have problem to Parsing the values to SQL statement, that Consists on the Run Time...
2
3204
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 with the javascript im using but i can print the correct values so why am i unable to use them to enter data to a database? sorry i am new to all this here is the updatedata.php file <?php session_start(); $host="localhost"; // Host...
0
9287
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9886
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9722
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6542
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.