Jump to content

z-victoria

Members
  • Posts

    9
  • Joined

  • Last visited

About z-victoria

  • Birthday 12/16/1988

Contact Methods

  • MSN
    zozo_x88x@msn.com

Profile Information

  • Gender
    Female
  • Location
    Bristol, UK

z-victoria's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey, yeah I figured that i've got my code fully functioning now I used if ($_SESSION['track'] == 1 && isset($_GET['yes'])) and if ($_SESSION['track'] == 1 && isset($_GET['no'])) instead of if = yes, else = no works fine now just styling up the page to make it look funky haha thanks loads
  2. ok i'll do that trust me to over complicate things lol. thanks for your help Solved
  3. Ohhhh shoot yeah your right, thanks. I put the switch in to avoid using millions of if statements lol, might just be the case that I will have to put those millions of if statements in instead of the switch, unless theres another way that you know of at all?
  4. Hey Guys, Please bear with me as I'm still rather new with PHP and have been chucked in the deep end a bit. Anyways, Im working on this mini version of a 20 questions game, however there's a slight hiccup somewhere along the line and I can't seem to suss it out. Say I say first question = yes it displays the 2nd question which is fine but then if I say the answer no to the second question is no it displays the 4th question but it should display question 5 which should be "Can you keep them as pets?" Demo here - http://s341350.neongrit.net/session_test.php Please be aware that it stores cookies!! I've been staring at it for hours now and its probably something really silly that I've missed knowing my luck lol but if anyone can point me in the right direction I would really appreciate it. Thank you. <?php session_set_cookie_params(2592000); //This sets the cookie for 30 days. session_start(); //initiate the session if(isset($_SESSION['track'])){ $_SESSION['track'] = $_SESSION['track']; } // else{ $_SESSION['track']=0; } ?> <html> <head> <title>Advanced Web 2013 || Creature Guessing Game</title> <style> /* start button styles */ #start{ background-color:#9F3; color:#fff; width:100px; height:30px; font-size:20px; border-width:2px; border-color:black; border-radius:10px; } #start:hover{ /*style changes slightly upon mouse hover over buttons*/ background-color:#9F6; border-width:1px; border-radius:10px; } /* styles for other buttons */ .buttons{ background-color:#666633; color:#fff; width:65px; height:25px; font-size:12px; font-weight:bold; border-width:2px; border-color:#black; border-radius: 10px; } .buttons:hover{ background-color:#999966; border-width:1px; border-radius:10px; } </style> </head> <body> <div class="position"> <h1>Creature Guessing Game</h1> <p>Hello<br> <br> Can I guess what creature your thinking of? <br> Click the button below to play!</p> <form method="post" action="session_test.php"> <input type="submit" name="start" value="Play!" id="start" /> </form> <div> <?php //Get array for Question 1 $first_question = "Does the creature live on land?"; //2-dimensional Array used here to ask certain questions based on answers from the user. In an array we have to point to arrays index. In this 2-dimensional array each question has two indexes (array number and question number) We access these later on. $question_array = array( array( 'Does it have wings?', 'Is it a type of mammal?'), array('Can it fly?', 'Can you keep them as pets?', 'Can they be found in the Artic?', 'Do they have fins?'), array('Are they nocturnal?','Do they live in Africa?','Are they reptillian?','Do they live in Australia?'), array('Do they have Paws?','Can you swim with them?','Can they eat people?','Do they have tentacles?') ); //Set variables for the functions $yes; // holds creature types based on yes answers from user $no; // holds creature types based on no answers from user $q_num = 0;; // holds the number of the question inside the array, default = 0 //first function asks questions 2-7 // question number is stored in $q_num variable, used by the function later. form name value uses $q_num var to pinpoint which question to move on to based on users answer .. function get_question($q_num) { echo "<form method ='GET' action='session_test.php'> <input type='submit' name='answer$q_num' value='Yes' class='buttons' /> <input type='submit' name='answer$q_num' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; echo $q_num; //$q_num ++; // adds 1 to the $q_num var after each question } //Second function asks questions 8-15 used in the switch statement // the variables $yes and $no store the final answer based on the users yes/no selection function get_final($yes,$no) { echo "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='$yes' class='buttons'> Yes </button> <button type='submit' name='answer' value='$no' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } //If start button has not been pressed, display nothing if (isset($_POST['start'])){ if(isset($_SESSION['track'])) { echo $_SESSION["track"]; echo $_SESSION["question"]; echo $_SESSION["form"]; } if($_SESSION['track']== 0) { echo "<div class='questions'> $first_question </div>"; echo "<div class='questions'><form method ='GET' action='session_test.php'> <input type='submit' name='yes' value='Yes' class='buttons' /> <input type='submit' name='no' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form></div>"; $_SESSION['track'] = 1; $_SESSION['question'] = $first_question; } } // If answer to question #1 is Yes ... Ask question #2 if ($_SESSION['track'] == 1 && isset($_GET['yes'])) { echo "<div class='questions'>{$question_array[0][0]}</div>"; //question 2 is located in array 0 at index 0 get_question(1);// see function set up above for explanation on using the different functions and what they do echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?yes=Yes' readonly></input>"; $_SESSION['track'] = 2; $_SESSION['question'] = $question_array[0][0]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <input type='submit' name='answer1' value='Yes' class='buttons' /> <input type='submit' name='answer1' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } // If answer to question #1 is No ... Ask question #3 if ($_SESSION['track'] == 1 && isset($_GET['no'])) { echo "<div class='questions'>{$question_array[0][1]}</div>"; // question 3 is located in array 0 at index 1 get_question(2); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?no=No' readonly></input>"; $_SESSION['track'] = 3; $_SESSION['question'] = $question_array[0][1]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <input type='submit' name='answer2' value='Yes' class='buttons' /> <input type='submit' name='answer2' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } // If answer to question #2 is Yes ... Ask question #4 switch($_SESSION['track'] == 2 && isset($_GET['answer1'])) { case 'Yes': echo "<div class='questions'>{$question_array[1][0]}</div>"; // question 4 is located in array 1 at index 0 get_question(3); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer1=Yes' readonly></input>"; $_SESSION['track'] = 4; $_SESSION['question'] = $question_array[1][0]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <input type='submit' name='answer3' value='Yes' class='buttons' /> <input type='submit' name='answer3' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; break; // If answer to question #2 is No ... Ask question #5 case 'No': echo "<div class='questions'>{$question_array[1][1]}</div>"; // question 5 is located in array 1 at index 1 get_question(4); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer1=No' readonly></input>"; $_SESSION['track'] = 5; $_SESSION['question'] = $question_array[1][1]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <input type='submit' name='answer4' value='Yes' class='buttons' /> <input type='submit' name='answer4' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } // If answer to question #3 is Yes .. Ask question #6 switch($_SESSION['track'] == 3 && isset($_GET['answer2'])) { case 'Yes': echo "<div class='questions'>{$question_array[1][2]}<div>"; // question 6 is located in array 1 at position 2 get_question(5); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer2=Yes' readonly></input>"; $_SESSION['track'] = 6; $_SESSION['question'] = $question_array[1][2]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <input type='submit' name='answer5' value='Yes' class='buttons' /> <input type='submit' name='answer5' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; break; // If answer to #3 is no ... Ask question #7 case 'No': echo "<div class='questions'>{$question_array[1][3]}</div>"; // question 7 is located in array 1 at position 3 get_question(6); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer2=No' readonly></input>"; $_SESSION['track'] = 7; $_SESSION['question'] = $question_array[1][3]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <input type='submit' name='answer6' value='Yes' class='buttons' /> <input type='submit' name='answer6' value='No' class='buttons' /> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } //**and so on and so forth...** // If answer to question #4 is Yes ... Ask question #8 switch($_SESSION['track'] == 4 && isset($_GET['answer3'])) { case 'Yes': echo "<div class='questions'>{$question_array[2][0]}</div>"; get_final('Owl','Pidgeon'); // see function set up above for explanation on using the different functions and what they do // if the answer to question 8 is Yes its a Eagle, if No then is a Parrot... These answers are atored in the $yes and $no vars inside the get_final() function. echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer3=Yes' readonly></input>"; $_SESSION['track'] = 8; $_SESSION['question'] = $question_array[2][0]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Owl' class='buttons'> Yes </button> <button type='submit' name='answer' value='Pidgeon' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; break; //Otherwise ask question #9 case 'No': echo "<div class='questions'>{$question_array[2][1]}</div>"; get_final('Ostrich','Penguin'); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer3=No' readonly></input>"; $_SESSION['track'] = 9; $_SESSION['question'] = $question_array[2][1]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Ostrich' class='buttons'> Yes </button> <button type='submit' name='answer' value='Penguin' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } // If answer to question #5 is Yes ... Ask question #10 switch($_SESSION['track'] == 5 && isset($_GET['answer4'])) { case 'Yes': echo "<div class='questions'>{$question_array[2][2]}</div>"; get_final('Snake','Dog'); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer4=Yes' readonly></input>"; $_SESSION['track'] = 10; $_SESSION['question'] = $question_array[2][2]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Snake' class='buttons'> Yes </button> <button type='submit' name='answer' value='Dog' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; break; //Otherwise ask question #11 case 'No': echo "<div class='questions'>{$question_array[2][3]}<div>"; get_final('Kangaroo','Lion'); // see above for expanation on the get_final() funstion echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer4=No' readonly></input>"; $_SESSION['track'] == 11; $_SESSION['question'] = $question_array[2][3]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Kangaroo' class='buttons'> Yes </button> <button type='submit' name='answer' value='Lion' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } // If answer to question #6 is Yes .. Ask question #12 switch($_SESSION['track'] == 6 && isset($_GET['answer5'])) { case 'Yes': echo "<div class='questions'>{$question_array[3][0]}</div>"; get_final('Polar Bear','Humpback Whale'); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer5=Yes' readonly></input>"; $_SESSION['track'] = 12; $_SESSION['question'] = $question_array[3][0]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Polar Bear' class='buttons'> Yes </button> <button type='submit' name='answer' value='Humpback Whale' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; break; //Otherwise ask question #13 case 'No': echo "<div class='questions'>{$question_array[3][1]}</div>"; get_final('Dolphin','Sea Otter'); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer5=No' readonly></input>"; $_SESSION['track'] == 13; $_SESSION['question'] = $question_array[3][1]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Dolphin' class='buttons'> Yes </button> <button type='submit' name='answer' value='Sea Otter' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } // If answer to question #7 is Yes ... Ask question #14 switch($_SESSION['track'] == 7 && isset($_GET['answer6'])) { case 'Yes': echo "<div class='questions'>{$question_array[3][2]}</div>"; get_final('Shark','type of harmless fish maybe?'); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer6=Yes' readonly></input>"; $_SESSION['track'] = 14; $_SESSION['question'] = $question_array[3][2]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Shark' class='buttons'> Yes </button> <button type='submit' name='answer' value='type of harmless fish maybe?' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; break; //Otherwise ask question #15 case 'No': echo "<div class='questions'>{$question_array[3][3]}</div>"; get_final('Jellyfish','Crocodile'); echo "Send to a friend: <input type='text' value='http://s341350.neongrit.net/web.php?answer6=no' readonly></input>"; $_SESSION['track'] = 15; $_SESSION['question'] = $question_array[3][3]; $_SESSION['form'] = "<form method ='GET' action='session_test.php'> <button type='submit' name='answer' value='Jellyfish' class='buttons'> Yes </button> <button type='submit' name='answer' value='Crocodile' class='buttons'> No </button> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; } //****// if (isset($_GET['answer'])) //If the final answer has been reached ... { echo "Its a "; print_r($_GET['answer']); // display final answer // *** error here echo alone doesnt seem to work so have used print_r function to show everything inside the array *** // echo "<br>"; echo "<form method ='GET' action='session_test.php'> <button type='submit' name='restart' value='restart' class='buttons'> Restart </button> </form>"; echo "<br><br>"; //echo a line break for spacing after answer **makes it look nicer** } // unset session if restart has been pressed if (isset($_GET['restart'])) { session_destroy(); // destroy session } ?> </body> </html>
  5. ahh i think thats what it is viewing the wrong page LOL, i've just put the new url and its showing the page it should but not the information which is probs because the script is unfinished at the moment...i'll put this on solved for now and come back if i get any more errors cheers for the advice
  6. thanks for you reply, and yeah what you said about the GET id is sorta what I want it to do, i'll worry about the rest of it later so just ignore all my rubbish up there, just tried your re-write and its still killing the script instead of continuing to send out the user profile information so is $id not holding the value? I'm well confused.
  7. hey guys i dont really know how to explain this but i'm trying to get my user profile page working but when im logged in the script kills and redirects to the index.php page i dont want it to do this, when username1 is logged in they can still view the profile if they click the link to the username2's profile and vise versa, i want guests to be able to view other profiles too but if they go straight to profile.php without setting the id of the user they want to view ...then its supposed to kill.. for the profile.php page i'm using the $_GET function to get the users id like so i dont no if theres any problems with this or not as im fairly new to PHP/SQL <?php session_start(); // Connect to database include_once "conn.inc.php"; // If coming from category page if ($_GET['id']) { $id = $_GET['id']; } else if (isset($_SESSION['id'])) { $id = $_SESSION['id']; } else { include_once "index.php"; exit();//kills script if user cannot be authenticated } $id = mysql_real_escape_string($id); $id = eregi_replace("`", "", $id); $sql = mysql_query("SELECT * FROM user_info WHERE id='$id'"); while($row = mysql_fetch_array($sql)){ $image = $row["imagelocation"]; $username = $row["username"]; $firstname = $row["firstname"]; $lastname = $row["lastname"]; $country = $row["country"]; $city = $row["city"]; $bio = $row["bio_body"]; } ?> the above code is just the PHP ive left out the html design etc where the sql row echos are etc and ive done row echos before so i know they're deffo not the problem the id field in my table is int(10) not null auto_increment primary key. for other pages where users have to be logged in to view im using sessions which are in auth_user.php which is included in pages that are restricted etc <?php session_start(); if ((isset($_SESSION['username']) && $_SESSION['username'] != "") || (isset($_SESSION['password']) && $_SESSION['password'] != "")) { //Do Nothing! } else { $redirect = $_SERVER['PHP_SELF']; header("Refresh: 5; URL=user_login.php?redirect=$redirect"); echo "You are currently not logged in, we are redirecting you, " . "be patient!<br>"; echo "(If your browser doesn’t support this, " . "<a href=\"user_login.php?redirect=$redirect\">click here</a>)"; die(); } ?> like i said i dont really know how to explain this but is the profile.php killing the script instead of showing the selected users profile because i need to use the same auth_user.php file in my profile.php instead of the $_GET? will username1 still be able to view username2 if i use that file..even as a guest? i've tried swapping it to sessions but the page don't seem to work with them either.... any tips would be very appreciated and i have searched everywhere for hours on end for help but dont seem to be getting anywhere cheers guys.
  8. OMG! I'm so flippin silly! $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass, $email, $country); forgot to add it on the end! Arghhh! thanks MasterACE14 LOL x
  9. Hey Guys, newbie here so bear with me Right basically I'm trying to get my default image location into the database but I'm getting a sql warning..."missing argument 5 for addnewuser in ...blah blah blah... on line 37" I've only been doing PHP and SQL for just under a month and hav'nt come accross this error before. My database table is in the following order: - username - password - email - country - imagelocation - id the addnewuser function is: function addNewUser($username, $password, $email, $country, $location){ global $conn; $q = "INSERT INTO user_info (username, password, email, country, imagelocation) VALUES ('$username', '$password', '$email', '$country', '$location')"; return mysql_query($q,$conn) or die(mysql_error()); line 37 is where the $q is and the image bit is further up my page of code so above the function.. $location = "images/avatars/default.jpg"; the rest of the script is working fine it's just that bit giving out the error and not storing the image location into the database any clues ??? - i've been trying to work it out for hours, searching on Google etc with no luck at all - might just be me being silly and missing a really tiny thing as per usual lol! thanks in advance guys x
×
×
  • 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.