Jump to content

MuphN

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by MuphN

  1. ginerjm yep you are right. I did some research and now I do understand the script. But not it gets stuck at 00:00 counter doesnt go. Just shows 00.00
  2. So. If I would do this. function secondPassed() { var minutes = Math.round((seconds - 30)/60); var remainingSeconds = seconds % 60; if (remainingSeconds < 10) { remainingSeconds = "0" + remainingSeconds; } //store seconds to cookie setCookie("my_cookie",seconds,5); //here 5 is expiry days document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds; if (seconds == 0) { clearInterval(countdownTimer); document.getElementById('countdown').innerHTML = "T"; $.ajax('includes/uhp.php', { //calls uhp.php? success: function(response) { //What this function does with response? $('#countdown').html("DUNE"); //This writes Dune in html countdown span right? } } setCookie('my_cookie', '', -1); } else { seconds--; } } Could you explain this one? Its not just to get the script working, I just need to understand so I wouldnt bother you next time guys.
  3. I do realise that, but I dont really imagine how to play with ajax like that. Could you help me?
  4. How can I make that js would trigger the script? The script is including the database, but js cant do that.
  5. True, how would you think I should do? I mean I though countdown with cookies will help, wouldnt it be better to make a timer with server side time so for example if timer started it gets the server time, adds +60 seconds to it and makes it the finishing time, how would I do that?
  6. by the <span id="countdown" class="timer"></span> - in other words it shows the outcome in this span.
  7. Hello, so I have trubble with one thing, I created a countdown with cookies and javascript, and I want to do something when it counts to 0. So I tryed adding a bit php to js. Hares what I got. My main.php page (lets say its main.php). <?php include_once 'includes/uhp.php'; ?> <script type="text/javascript"> function setCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname + "=" + cvalue + "; " + expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name)==0) return c.substring(name.length,c.length); } return ""; } //check existing cookie cook=getCookie("my_cookie"); if(cook==""){ //cookie not found, so set seconds=60 var seconds = 60; }else{ seconds = cook; console.log(cook); } function secondPassed() { var minutes = Math.round((seconds - 30)/60); var remainingSeconds = seconds % 60; if (remainingSeconds < 10) { remainingSeconds = "0" + remainingSeconds; } //store seconds to cookie setCookie("my_cookie",seconds,5); //here 5 is expiry days document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds; if (seconds == 0) { clearInterval(countdownTimer); document.getElementById('countdown').innerHTML = "<?php uhpn($mysqli); ?>"; setCookie('my_cookie', '', -1); } else { seconds--; } } var countdownTimer = setInterval(secondPassed, 1000); </script> <span id="countdown" class="timer"> </span> And thats my uhp.php that I included at the top. <?php include_once 'db_connect.php'; include_once 'functions.php'; sec_session_start(); function uhpn($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET count = count+1 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); // check if the query did execute and that it affected a row if ($stmt->execute() && $mysqli->affected_rows > 0) { exit; } } return false; } So I tryed setting that it would only say like TEST when the counter hits 0, it works. Everything is fine, but whenever I add the php part to the js timer end. It runs the script but it runs allways when u refresh it, but it doesnt trigger when its 00:00, and when refresh it kills the script. So I think its my php foult for some reason, it only runs the php, it doesnt cares about js part. Any help, thank you in advanced!
  8. Thank you for you response. But how can I make it that it would call like two or even all rows from database and make it different I mean. function getbase($mysqli) { if ($stmt = $mysqli->prepare("SELECT level, xp, somthing, else, blah FROM members WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 5) { $stmt->bind_result( $s, $x, $b, $f, $g); $stmt->fetch(); return $s, $x, $b, $f, $g; } } return false; } Should it be like that, Sorry Im kinda sleepy. Got it, makes sense. lu2,3,4.... actually does, it uploads some numbers to database, I guess I should use one querry somehow aswell? function lvl2($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET level = 2, xp = xp-200 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); if ($stmt->execute() && $mysqli->affected_rows > 0) { header('Location: index.php'); exit; } } return false; } -------------------- function lvl3($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET level = 3, xp = xp-500 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); if ($stmt->execute() && $mysqli->affected_rows > 0) { header('Location: index.php'); exit; } } return false; } =-------------- and so on. I added some lines to understand it more easy. function uXL($mysqli) { $lu2 = lvl2($mysqli); $lu3 = lvl3($mysqli); $lu4 = lvl4($mysqli); $lu5 = lvl5($mysqli); $lu6 = lvl6($mysqli); $lu7 = lvl7($mysqli); $lu8 = lvl8($mysqli); $lu9 = lvl9($mysqli); $lu10 = lvl10($mysqli); $xp = getXp($mysqli); $lvl = getLvl($mysqli); $nolvl = "You don't have enough experiance points!"; $maxlvl = "You are allready maximum level!"; //If level is 1 if ($lvl == 1) { //and xp is more or equal then 200 if($xp >= 200 ){ //does this function. $lu2; }else { //If u dont have 200 xp points it says that u dont have it. echo $nolvl; } }else if ($lvl == 2) { if($xp >= 500 ){ $lu3; }else { echo $nolvl; } }else if($lvl == 3) { if($xp >= 1000 ){ $lu4; }else { echo $nolvl; } }else if($lvl == 4) { if($xp >= 1700 ){ $lu5; }else { echo $nolvl; } }else if($lvl == 5) { if($xp >= 2500 ){ $lu6; }else { echo $nolvl; } }else if($lvl == 6) { if($xp >= 3200 ){ $lu7; }else { echo $nolvl; } }else if($lvl == 7) { if($xp >= 4000 ){ $lu8; }else { echo $nolvl; } }else if($lvl == { if($xp >= 5000 ){ $lu9; }else { echo $nolvl; } }else if($lvl == 9) { if($xp >= 6200 ){ $lu10; }else { echo $nolvl; } }else{ //level 10 or more or 0 shows that ur maximum level allready. echo $maxlvl; } } if(isset($_POST['lvlup'])) //If button is clicked, it does the function. { if(uXL($mysqli)) { //If the querry is sucsessifull it shows that u gained a level. echo "You have gained a level!"; } else { // if Not, then not. echo "some prob!"; } }
  9. I dont get it before, it gets after it, it selects the ID by taking it from seesion $user_id = $_SESSION['user_id']; - this sets the user_id to Session Id, so it takes the ID from ur current session. The session starts when its set, its set on the page where u need to do stuff. $stmt->bind_param('i', $user_id); - This sets the user_id for the ? one at the prepares. It prepers frists then sets the user id from session and then executes the query. If Im correct, ughh bad at explaining.
  10. function getLvl($mysqli) { if ($stmt = $mysqli->prepare("SELECT level FROM members WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { $stmt->bind_result( $lvl); $stmt->fetch(); return $lvl; } } return false; } No error, just always goes for $ul2; nothing else, doesnt matter if you are lvl 3 or lvl 5
  11. Hello I have a problem. I think I cant do that, how can I go arround this, because in javascript I guess u can go else if how meny times u want to, but in php it shows an error, and cant find the mistake is it else if's or something else thats causing the trubble? function uXL($mysqli) { $lu2 = lvl2($mysqli); $lu3 = lvl3($mysqli); $lu4 = lvl4($mysqli); $lu5 = lvl5($mysqli); $lu6 = lvl6($mysqli); $lu7 = lvl7($mysqli); $lu8 = lvl8($mysqli); $lu9 = lvl9($mysqli); $lu10 = lvl10($mysqli); $xp = getXp($mysqli); $lvl = getLvl($mysqli); $nolvl = "You don't have enough experiance points!"; $maxlvl = "You are allready maximum level!"; if ($lvl == 1) { if($xp >= 200 ){ $lu2; }else { echo $nolvl; } }else if ($lvl == 2) { if($xp >= 500 ){ $lu3; }else { echo $nolvl; } }else if($lvl == 3) { if($xp >= 1000 ){ $lu4; }else { echo $nolvl; } }else if($lvl == 4) { if($xp >= 1700 ){ $lu5; }else { echo $nolvl; } }else if($lvl == 5) { if($xp >= 2500 ){ $lu6; }else { echo $nolvl; } }else if($lvl == 6) { if($xp >= 3200 ){ $lu7; }else { echo $nolvl; } }else if($lvl == 7) { if($xp >= 4000 ){ $lu8; }else { echo $nolvl; } }else if($lvl == { if($xp >= 5000 ){ $lu9; }else { echo $nolvl; } }else if($lvl == 9) { if($xp >= 6200 ){ $lu10; }else { echo $nolvl; } }else{ echo $maxlvl; } } Everything works good I tested it take the $lvl and takes the $xp but it always goes for if lvl 1 and lu2 nothing more, I did try to set in database the level 3 for testing further, but it jumped into first one again, doesnt matter witch one I set it always leads to lu2; for some reason.. Help me see the syntax mistake.
  12. Hello. I need help with my js, basicly its js count down that counts to zero, I think it should be correct, umm I dont really understand the part where it says if (M > 30) { - I understand that if minutes is higher then 30 mins, y = sets a, but I need to make it that if minutes reaches 00:00 add php script <?php $uploadToDB ?> and restarts the countdown. How can I do that? Hares the script of js countdown. <HTML> <HEAD> <TITLE>Count Down Timer</TITLE> <script> //add leading zeros setInterval(function() { function addZero(i) { if (i < 10) { i = "0" + i; } return i; } var x = document.getElementById("timer"); var d = new Date(); var s = (d.getSeconds()); var m = (d.getMinutes()); var a = addZero(60 - 60); var b = addZero(60 - m); var c = (60 - s); if (m > 30) { y = a; } if (m == 0) { return true; } var t = y + (":" + addZero(c)); x.innerHTML = t; }, 250); </script> </HEAD> <BODY> <div align="center" id="timer" style='color:black;font-size:24px;' ></div> </BODY> </HTML>
  13. Hello. I need information. I know how to create timer with javascript, and i managed to create a timmer with cookies as well, but not perfectly working yet, so that if user would restart the page it would still continue after it, but I need to make that it would still continue counting down if the page closed or PC even shuted down, how can I make that? What do I need to use, need your help on this one.. Thanks guys, waiting for a response.
  14. Hello. So I have a problem. I have a counter that counts down to 0. And you can set the numbers to count to urself, but I need to make it that it wouldn't refresh when you refresh the whole page. I guess I should use SESSION or something, but I cant make it work for some reason. /* Function to display a Countdown timer with starting time from a form */ // sets variables for minutes and seconds var ctmnts = 0; var ctsecs = 0; var startchr = 0; // used to control when to read data from form function countdownTimer() { // http://coursesweb.net/javascript/ // if $startchr is 0, and form fields exists, gets data for minutes and seconds, and sets $startchr to 1 if(startchr == 0 && document.getElementById('mns') && document.getElementById('scs')) { // makes sure the script uses integer numbers ctmnts = parseInt(document.getElementById('mns').value) + 0; ctsecs = parseInt(document.getElementById('scs').value) * 1; // if data not a number, sets the value to 0 if(isNaN(ctmnts)) ctmnts = 0; if(isNaN(ctsecs)) ctsecs = 0; // rewrite data in form fields to be sure that the fields for minutes and seconds contain integer number document.getElementById('mns').value = ctmnts; document.getElementById('scs').value = ctsecs; startchr = 1; document.getElementById('btnct').setAttribute('disabled', 'disabled'); // disable the button } // if minutes and seconds are 0, sets $startchr to 0, and return false if(ctmnts==0 && ctsecs==0) { startchr = 0; document.getElementById('btnct').removeAttribute('disabled'); // remove "disabled" to enable the button /* HERE YOU CAN ADD TO EXECUTE A JavaScript FUNCTION WHEN COUNTDOWN TIMER REACH TO 0 */ return false; } else { // decrease seconds, and decrease minutes if seconds reach to 0 ctsecs--; if(ctsecs < 0) { if(ctmnts > 0) { ctsecs = 59; ctmnts--; } else { ctsecs = 0; ctmnts = 0; } } } // display the time in page, and auto-calls this function after 1 seccond document.getElementById('showmns').innerHTML = ctmnts; document.getElementById('showscs').innerHTML = ctsecs; setTimeout('countdownTimer()', 1000); } //--> <form> Minutes: <input type="text" id="mns" name="mns" value="0" size="3" maxlength="3" /> Seconds: <input type="text" id="scs" name="scs" value="0" size="2" maxlength="2" /><br/> <input type="button" id="btnct" value="START" onclick="countdownTimer()"/> </form> Countdown Timer: <span id="showmns">00</span>:<span id="showscs">00</span> Hare java and html.
  15. Oh, Now I understand, first I made that add5 if as u told me but I changed it yeastirday, and now I understand what you meant with UPDATE. I understand now. Thank you gratefull for all who made effort to help me
  16. db_connecti.php <?php include_once 'psl-config.php'; // As functions.php is not included $mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE); ?> ------------------- psl-config.php <?php define("HOST", "localhost"); // The host you want to connect to. define("USER", "gasdasda"); // The database username. define("PASSWORD", "masdasdfgsd"); // The database password. define("DATABASE", "asfugm"); // The database name. ?> but its defined as mysqli, It shouldnt be a prob I guess. I did remove the include, But it still doesnt add things to database, Maybe the '$str' + 5 is wrong, or the script is correct afterall?
  17. Thank you for showing my mistakes, so I created a script newly now, its not working, but IM trying to learn it now. As I understood the tut from a site. This should be correct? <?php include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); $str = getStr($mysqli); $agi = getAgi($mysqli); $range = getRange($mysqli); $host="localhost"; $username="aassdasda"; $password="maasdasd3"; $database="asdasrudsfm"; if(isset($_POST['add5'])){ mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $user_id = $_SESSION['user_id']; $query = "UPDATE members SET str = '$str + 5', agi = '$agi + 5', `range` = '$range + 5' WHERE id = '$user_id'"; if(mysql_connect($host,$username,$password)) { echo "The db has been connected, going to update"; mysql_query($query); if(mysql_query($query)) { echo "Querry has been updated!"; mysql_close(); }else{ echo "The querry didint update.."; mysql_close(); } }else{ echo "The connection was lost, it didint connect"; mysql_close(); } } ?> It shows no errors, that its sucsessiful, but it dosnt actually update the db.
  18. I understand now, but for some reason my script is not working. I made fc.php with inside: <?php include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); $str = getStr($mysqli); $agi = getAgi($mysqli); $range = getRange($mysqli); if(isset($_POST['add5'])){ function getIns($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET str = ?+5, agi = ?+5, `range` = ?+5 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('iiii', $str, $agi, $range, $user_id); if (!$insert_stmt->execute()) { header('Location: ../error.php?err=Registration failure: INSERT'); } } header('Location: ./register_success.php'); } } ?> and then added this <?php include_once 'includes/db_connect.php'; include_once 'includes/functions.php'; include_once 'system/fc.php'; sec_session_start(); ?> <!DOCTYPE html> <html> <head> </head> <body> <form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>" method="post"> <input type="submit" name="add5" value="Add +5" /> </form> </body> </html> But it doesnt react, just doesnt add + 5 to my database colums.
  19. Hello. So Im trying to make an update for exemple on click, that would update my database, but it doesnt function. button just dissapears. thats all. <?php $clicked = getIns($mysqli); ?> <button type="button" onclick="<?php $clicked ?>">+5StatsUp</button> ---------------------------------------------------------- $strp = getStr($mysqli) + 5; $agip = getAgi($mysqli) + 5; $rangep = getRange($mysqli) + 5; function getIns($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET str = ?, agi = ?, `range` = ? WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('iiii', $strp, $agip, $rangep, $user_id); if (!$insert_stmt->execute()) { header('Location: ../error.php?err=updateFailled: INSERT'); } } header('Location: ./update_success.php'); } What it should do: Update members - str, agi, range + 5 where id is user id. Hmmmm can you guys tell me whats wrong with my code? :/
  20. i though so, that u can find the problem, by checking the code. Thanks dude, u save my a** again. Gratefull! )
  21. It doesn't show any errors, just doesn't add those numbers to detabase, it doesnt add enything after I added those. maybe I made a syntax mistake, maybe I selected the vars wrong? When I try to register. It shows Sucsessifuly registered. I got to db, no new user registered. Could be that I made a mistake in detabase, for exemple: all these new vars are numbers. and to detabase I added those collums with property INI(100) - 100 length, so maybe it doesnt add because there is some colums witch is wrong.
  22. It sends the $username, $email, $password, $random_salt, $drop, $hp, $level, $str to detabase, from inputs. // Insert the new user into the database if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt, Race, health, level, str, agi, range) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $insert_stmt->bind_param('ssssssssss', $username, $email, $password, $random_salt, $drop, $hp, $level, $str, $agi, $range); // Execute the prepared query. if (! $insert_stmt->execute()) { header('Location: ../error.php?err=Registration failure: INSERT'); } } header('Location: ./register_success.php'); } And I need to add custom vars to the db, like $hp to healt
  23. No problem, I guess its my own fault though.
  24. okey, so I need to create simple numbers to go to the detabase on register page. for exemple: <?php include_once 'db_connect.php'; include_once 'psl-config.php'; $error_msg = ""; if (isset($_POST['username'], $_POST['email'], $_POST['p'])) { // Sanitize and validate the data passed in $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING); $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); $email = filter_var($email, FILTER_VALIDATE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { // Not a valid email $error_msg .= '<p class="error">The email address you entered is not valid</p>'; } $password = filter_input(INPUT_POST, 'p', FILTER_SANITIZE_STRING); if (strlen($password) != 128) { // The hashed pwd should be 128 characters long. // If it's not, something really odd has happened $error_msg .= '<p class="error">Invalid password configuration.</p>'; } $drop = filter_input(INPUT_POST, 'my_dropdown', FILTER_SANITIZE_STRING); // Username validity and password validity have been checked client side. // This should should be adequate as nobody gains any advantage from // breaking these rules. // $prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1"; $stmt = $mysqli->prepare($prep_stmt); if ($stmt) { $stmt->bind_param('s', $email); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { // A user with this email address already exists $error_msg .= '<p class="error">A user with this email address already exists.</p>'; } } else { $error_msg .= '<p class="error">Database error</p>'; } // TODO: // We'll also have to account for the situation where the user doesn't have // rights to do registration, by checking what type of user is attempting to // perform the operation. if (empty($error_msg)) { // Create a random salt $random_salt = hash('sha512', uniqid(openssl_random_pseudo_bytes(16), TRUE)); // Create salted password $password = hash('sha512', $password . $random_salt); $hp = 100; $level = 1; $str = 10; $agi = 10; $range = 10; // Insert the new user into the database if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt, Race, health, level, str, agi, range) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $insert_stmt->bind_param('ssssssssss', $username, $email, $password, $random_salt, $drop, $hp, $level, $str, $agi, $range); // Execute the prepared query. if (! $insert_stmt->execute()) { header('Location: ../error.php?err=Registration failure: INSERT'); } } header('Location: ./register_success.php'); } }?> This is my whole register.inc page. As you know on other page there is a registraton form, which results get hare and stores in to detabase, dont really know how to explain it. $hp = 100; $level = 1; $str = 10; $agi = 10; $range = 10; This is just numbers that should be inserted into detabase, but after I added those for some reason it doesn't store them in the db. Sorry for leaving not much info.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.