|A mysql query("UPDATE") Problem|
I'm learning PHP, JS and mySQL and I'm having trouble putting it all together.
I've created a JS countdown timer which is set using:
The three variables (h,m,s) contain values I'm retrieving from my database, which is working correctly.
However, I can't seem to piece together a way to send the new values back to the server to be retrieved again on the next loop.
Here is my current (watered down - sorry if it's still a bit lengthy) code:
|var serverTime = '<?php print date("F d, Y H:i:s", time())?>' |
var timeLeft = new Date(serverTime)
var timeLeft1 = timeLeft
var h = //I'm pulling this value from timer_hour in my database.
var m = //I'm pulling this value from timer_minutes in my database.
var s = //I'm pulling this value from timer_seconds in my database.
//Uses the values from the database to set the timer.
//Add leading zero.
var HHMMSSstring=(digits.toString().length==1)? "0"+digits : digits;
//Run the timer in a loop and display it.
var timeString1 = HHMMSS(timeLeft1.getHours())+":"+HHMMSS(timeLeft1.getMinutes())+":"+HHMMSS(timeLeft1.getSeconds());
//Reduce the seconds by 1 every time this function loops.
/*I've tried a few methods to UPDATE the "timer_*" fields but here is my latest attempt - sending the new timeLeft1 values to hidden inputs on the page. Like I said, it doesn't work but it should at least illustrate what I'm trying to do. These ID's are defined on the page.*/
//Send new timeLeft1 values back to the server. This is giving me a syntax error.
$con = mysql_connect("servername","username","password");
die('Could not connect: ' . mysql_error());
$hours = "getElementById('hours1')"
$minutes = "getElementById('minutes1')"
$seconds = "getElementById('seconds1')"
SET timer_hour='$hours', timer_minutes='$minutes', timer_seconds='$seconds'
//Stop the displayTimer1() loop.
The reason I'm using my database to house the h,m,s values is that the user will be able to change the countdown time (timeLeft1) and that new time should show for all other users. That's my end goal, so if I'm going about it the wrong way then I'm open for suggestions.
Thanks for taking a look!
After re-reading my post above I don't think I was very clear about what I'm trying to do; sorry about that. Hopefully this will explain a bit better (and briefer).
Simply put, I need to send the hours, minutes and seconds values (contained in my timeLeft1 variable) to corresponding fields in a database table.
|UPDATE tablename |
SET timer_hour='timeLeft1.getHours()', timer_minutes='timeLeft1.getMinutes()', timer_seconds='timeLeft1.getSeconds()'
Any suggestions would be greatly appreciated. Thanks!