Jump to content

dink87522

Members
  • Posts

    142
  • Joined

  • Last visited

    Never

Everything posted by dink87522

  1. I get Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/geotwe/public_html/question.php:45) in /home/geotwe/public_html/question.php on line 512 I process it at the top. However I need to send data from the middle of my script.
  2. I have a script in my PHP page which checks if a question is answered correctly. This is checked when the user submits the Submit button. I want to be able to keep a running score of the number of questions correct. I place this in a variable, however how do I then get that variable to the next page? I can't use a cookie as I can't modify the http headers there with it being near the end of the page. I was thinking of using a hidden field value, however how do I then send that to the next page (the user has already clicked submit - when checking to see if they do or don't have the right answer). Thoughts or ideas?
  3. This is on another server, not mine.
  4. I don't knwo the options.
  5. I don;t knwo the name of the option.
  6. index.php?option=AAA how do I find what other options are available? i.e. BBB if it exists etc?
  7. Still doesn't work
  8. I have $servername = "localhost"; $username = "admin_admin"; $password = "admin"; $dbCon = mysql_connect($servername, $username, $password); if (!$dbCon) { die(); } $userID = "a"; $score = 33; $ageGroup = "mm"; $dateTimeStamp = "2345432"; mysql_select_db("admin_GTWE") or die(mysql_error()); mysql_query("INSERT INTO 'Highscores' (userID, score, ageGroup, saveTimeDate) VALUES($userID, $score, $ageGroup, $dateTimeStamp) "); except it doesn't work (althoguh nor does it throw any errors). The database details are defiantly correct and I can connect to it. The table exists. The rows exist. However I do have another column first called ID which is the priamry key?
  9. It works in IE, but not Firefox???
  10. How do I delete a cookie. I have setcookie("questionCount", time() -3600); and are trying to delete the cookie questionCount although it doesn't work.
  11. I done that, although the code does not work still.
  12. <?php // FUNCTIONS function stat_01($stat_01_handle, $answer_result){ global $stat_01_handle, $answer_result; echo("<br /> stat_01_handle: $stat_01_handle"); echo("<br /> answer_result: $answer_result <p>"); $stat_01_file = "statistics01.txt"; $stat_01 = fopen($stat_01_file, "r"); $stat_01_data = fread($stat_01, filesize($stat_01_file)); fclose($stat_01); $stat_01 = fopen($stat_01_file, "w"); $stat_01_raw = explode("h", $stat_01_data); [b]print_r($stat_01_data);[/b] echo ("<p>Data: ".$stat_01_raw[$stat_01_handle]); $stat_01_temp = $stat_01_raw[$stat_01_handle]; $stat_01_pieces = explode(",", $stat_01_temp); echo("<p> Exploded pieces: ".$stat_01_pieces[0]); // $stat_01_pieces[1] = question/array handle echo("<p> Exploded pieces: ".$stat_01_pieces[1]); // $stat_01_pieces[1] = number of times correct echo("<p> Exploded pieces: ".$stat_01_pieces[2]); // $stat_01_pieces[2] = number of times incorrect if ($answer_result == 1){ // User answered the question correctly $stat_01_pieces[1] = ($stat_01_pieces[1] + 1); // Adds 1 to the correct tally statistic for that question }else{ $stat_01_pieces[2] = ($stat_01_pieces[2] + 1); // Adds 1 to the incorrect tally statistic for that question } //$a = "h".$stat_01_pieces[0].",".$stat_01_pieces[1].",".$stat_01_pieces[2]; //$stat_01_data[$stat_01_handle] = $a; [b]print_r($stat_01_data);[/b] echo("A: ".$a); echo("SH: ".$stat_01_raw[$stat_01_handle]); for fwrite($stat_01, $stat_01_raw); fclose($stat_01); } ?> The data is in the first array when I print it. However by the end of the function it is no longer in that array (I need it be be, while I have changed on of the contents of one of the array values). When I try to print the array at the end the data is not in an array, why??? How can I achieve what I mentioned above (change the contents of one of the array values). Thanks
  13. ? Otherwise do do I print the contents of an array to a text file?
  14. I am getting the following error when I go to write.close to my file. "Warning: fwrite(): 2 is not a valid stream resource in /home/dinksoft/public_html/question3.php on line 513 Warning: fclose(): 2 is not a valid stream resource in /home/dinksoft/public_html/question3.php on line 514" I chmoded the file 777 permissions. I am writing an array to a file, could that be causing a problem? $stat_01_data[$stat_01_handle] = "h".$stat_01_handle.",".$stat_01_pieces[1].",".$stat_01_pieces[2]; fwrite($stat_01, $stat_01_data); fclose($stat_01);
  15. Thanks, that si exactly what I was after. Simpler than I thought it would be.
  16. I have a logn string of data, i.e. 44a542a43a453a1234a etc.. and are exploding it with 'a' as the break. However I only want 20 pieces of this data in my array (the first 20). How do I go about this?
  17. Thanks, I'll try that. I was not aware of the in_array function.
  18. The point of this function is to not give the user a question they have had in the previous 20 questions. However it simply does not work (i.e. you do get a question you've had in the most 20) and I can't see why. I am trying to check if $rnd has been in the previous 20 (stored from a cookie and which is retrieving that info successfully) and if so, select a new $rnd number and check it etc... Any help would be much appreciated. <?php $rnd = rand(1, 203); //recentQuestionsPop($rnd); $checked = ""; $recentlyAnswered = $_COOKIE["Recently_answered"]; $recentQuestions = explode("|", $recentlyAnswered); while ($checked != "1"){ $rnd = rand(1, 203); //$recentQuestions = explode("|", $recentlyAnswered); $checked = recentQuestionsPop($rnd); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function recentQuestionsPop($rnd){ $checked = "1"; switch ($rnd){ case "$recentQuestions[0]"; if ($rnd == $recentQuestions[0]){ $checked = "0"; } break; case "$recentQuestions[0]"; if ($rnd == $recentQuestions[0]){ $checked = "0"; } break; case "$recentQuestions[1]"; if ($rnd == $recentQuestions[1]){ $checked = "0"; } break; case "$recentQuestions[2]"; if ($rnd == $recentQuestions[2]){ $checked = "0"; } break; case "$recentQuestions[3]"; if ($rnd == $recentQuestions[3]){ $checked = "0"; } break; case "$recentQuestions[4]"; if ($rnd == $recentQuestions[4]){ $checked = "0"; } break; case "$recentQuestions[5]"; if ($rnd == $recentQuestions[5]){ $checked = "0"; } break; case "$recentQuestions[6]"; if ($rnd == $recentQuestions[6]){ $checked = "0"; } break; case "$recentQuestions[7]"; if ($rnd == $recentQuestions[7]){ $checked = "0"; } break; case "$recentQuestions[8]"; if ($rnd == $recentQuestions[8]){ $checked = "0"; } break; case "$recentQuestions[9]"; if ($rnd == $recentQuestions[9]){ $checked = "0"; } break; case "$recentQuestions[10]"; if ($rnd == $recentQuestions[10]){ $checked = "0"; } break; case "$recentQuestions[11]"; if ($rnd == $recentQuestions[11]){ $checked = "0"; } break; case "$recentQuestions[12]"; if ($rnd == $recentQuestions[12]){ $checked = "0"; } break; case "$recentQuestions[13]"; if ($rnd == $recentQuestions[13]){ $checked = "0"; } break; case "$recentQuestions[14]"; if ($rnd == $recentQuestions[14]){ $checked = "0"; } break; case "$recentQuestions[15]"; if ($rnd == $recentQuestions[15]){ $checked = "0"; } break; case "$recentQuestions[16]"; if ($rnd == $recentQuestions[16]){ $checked = "0"; } break; case "$recentQuestions[17]"; if ($rnd == $recentQuestions[17]){ $checked = "0"; } break; case "$recentQuestions[18]"; if ($rnd == $recentQuestions[18]){ $checked = "0"; } break; case "$recentQuestions[19]"; if ($rnd == $recentQuestions[19]){ $checked = "0"; } break; } return $checked; } ?>
  19. This code gives the maximum 30 second execution error. I am confused as to why, however one possible solution may be if the cookie does not exist if the user had not visited the site before (however I have the cookie and still get this same error). How do I fix the below code so it works and how do I check for a cookie on a user's computer (I know how to call a cookie, although how do you check if it does or does not exist? ) .Thanks. <?php $rnd = rand(1, 203); //recentQuestionsPop($rnd); $checked = ""; $recentlyAnswered = $_COOKIE["Recently_answered"]; $recentQuestions = explode("|", $recentlyAnswered) while ($checked != "1"){ // $rnd = rand(1, 203); recentQuestionsPop($rnd); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function recentQuestionsPop($rnd){ $checked = "1"; switch ($rnd){ case "$recentQuestions[0]"; if ($rnd == $recentQuestions[0]){ $checked = "0"; } break; case "$recentQuestions[1]"; if ($rnd == $recentQuestions[1]){ $checked = "0"; } break; case "$recentQuestions[2]"; if ($rnd == $recentQuestions[2]){ $checked = "0"; } break; } return $checked; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ ?>
  20. I got it working. I was placing it only at the top of the Body tags, not the very top.
  21. I can't work it out. Even if I place it at the top of my file it won't work. What I want to do is find a random number and then add that to the cookie (then next time we load that page we read that random number). <?php $rnd = rand(1, 203); $qCorrect = $rnd; setcookie("questionsCorrect", $qCorrect);
  22. I am trying to set a cookie with setcookie("questionsCorrect", $qCorrect); That is the only code for it on the page although the page in the browser gives the warning "Warning: Cannot modify header information - headers already sent by (output started at /home/dinksoft/public_html/question.php: in /home/dinksoft/public_html/question.php on line 439"
  23. I fixed it by removing that last break statement in the second switch. Why did this fix it though? As http://www.tizag.com/phpT/switch.php shows it as being acceptable as having a break there.
  24. Parse error: syntax error, unexpected T_BREAK in /home/dinksoft/public_html/deckShuffler.php on line 67 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Deck Shuffler</title> </head> <body> <!-- Simulates the shuffling of a standard 52 card deck and deals one random card --> <?php $cardNumber = rand(1, 13); // 1 = Ace, 11 = Jack, 12 = Queen, 13 = King, all others equal their face value $cardSuit = rand(1, 4); // 1 = Hearts, 2 = Diamonds, 3 = Spades, 4 = Clubs switch ($cardNumber){ case "1": $card = "Ace"; break; case "2": $card = "Two"; break; case "3": $card = "Three"; break; case "4": $card = "Four"; break; case "5": $card = "Five"; break; case "6": $card = "Six"; break; case "7": $card = "Seven"; break; case "8": $card = "Eight"; break; case "9": $card = "Nine"; break; case "10": $card = "Ten"; break; case "11": $card = "Jack"; break; case "12": $card = "Queen"; break; case "13": $card = "King"; break; } // Identifies the card suit switch ($cardSuit){ case "1": $suit = "Hearts"; break; case "2": $suit = "Diamonds"; break; case "3": $suit = "Spades"; break; case "4": $suit = "Clubs"; break; } echo("Card dealt: $card of $suit") ?> </body> </html>
×
×
  • 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.