fierdor Posted December 30, 2008 Share Posted December 30, 2008 I am making this online quiz type thing where you keep answering levels to go the next one. The page layout has a level bar which has numbers going from 1 to 30.When sumone reaches level 5 suppose he gets the links from levels 1 to 5.Now suppose he clicks on level 1 he should go to level 1 but he should get the link to level 5 on the page of level 1.On each page i am doing a level check to find whether the person has actually passed the previous level and i keep updating his level.My code is as follows <?php session_start(); include("database.php"); include("auth.php"); $username=$_SESSION['SESS_MEMBER_ID']; $query=mysql_query("SELECT level FROM members WHERE member_id='$username'"); $x=mysql_fetch_assoc($query); if ($x['level']>=2) { if(isset($_POST['name'])) { $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myst",$con); $result = mysql_query("SELECT * FROM answers WHERE level='2'"); while ($row = mysql_fetch_array($result)) { $a=$row['answer']; $b=$_POST['name']; if ($a==$b) { $username=$_SESSION['SESS_MEMBER_ID']; $query=mysql_query("SELECT level FROM members WHERE member_id='$username'"); $x=mysql_fetch_assoc($query); if ($x['level']<=2) { $username = $_SESSION['SESS_MEMBER_ID'] ; mysql_query("UPDATE members SET level = '3' WHERE member_id ='$username'"); } header("Location:http://localhost/myst/code3.php"); exit; } else { header("Location:http://localhost/myst/right2.php"); exit; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> <!-- function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); // --> </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Level 1</title> <link href="myst.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="#999999"> <div id="Layer1" style="position:absolute; left:145px; top:15px; width:258px; height:72px; z-index:1"> <h1><font face="Jokerman, Chiller" size="7" color="#FF0000">MYST</font></h1> </div> <div id="Layer2" style="position:absolute; left:145px; top:97px; width:352px; height:22px; z-index:2">Please enter the tagline here</div> <img src="http://localhost/myst/revo.jpg" width="98" height="136"> <hr width="805"> <p class="onlymyst"> </p> <!--No clue here--> <div id="Layer3" style="position:absolute; width:183px; height:373px; z-index:3; left: 11px; top: 212px"> <table width="101%" border="1"> <tr> <td > <div align="center"><b><font color="#0000CC">About Us</font></b></div> </td> </tr> </table> <table width="101%" border="1" height="351"> <tr> <td> </td> </tr> </table> </div> <div id="Layer4" style="position:absolute; width:805px; height:27px; z-index:4; left: 10px; top: 175px"> <table width="100%" border="1"> <tr> <td>Level <a href="welcome.php">1</a>..<?php if($x>=2){?><a href="right.php">2</a>..<?php } if($x>=3){?><a href="code3.php">3</a><?}?>..4..5..6..7..8..9..10..11..12..13..14..15..16..17 ..18..19..20..21..22..23..24..25..26..27..28..29..30..Want more???? </td> </tr> </table> </div> <h1> </h1> <div id="Layer5" style="position:absolute; width:387px; height:381px; z-index:5; left: 219px; top: 211px"> <p><b><font face="Courier New, Courier, mono" size="4">Question:</font></b></p> <p> <font size="3" face="Verdana, Arial, Helvetica, sans-serif"><b><font size="2">Try try till you suceed!!</font></b></font> </p> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Answer: <input type="text" name="name" size="30" /> <input type="submit" value="Submit" name="submit" /> </form> <div id="Layer7" style="position:absolute; width:388px; height:28px; z-index:1; left: 0px; top: 354px"> <table width="100%" border="1"> <tr> <td>Lets go <a href="http://technovanza.org/">Technovanza '09</a> - The technical event of VJTI</td> </tr> </table> </div> </div> <div id="Layer6" style="position:absolute; width:196px; height:377px; z-index:6; left: 615px; top: 211px"> <table width="101%" border="1"> <tr> <td> <div align="center"><b><font color="#FF0000">Updates!!!</font></b></div> </td> </tr> </table> <table width="101%" border="1" height="137"> <tr> <td height="158"> <p>So you think its quite difficult solving these few lines. We're here to help you out. Want to know more??????</p> <form name="form1" method="post" action="forum.php"> <center><input type="submit" name="Submit" value="Click Here!!!"></center> </form> <p> </p> </td> </tr> </table> <table width="101%" border="1"> <tr> <td> <div align="center"><b><font color="#0000FF"><a href="scoreboard.php">Scoreboard</a></font></b></div> </td> </tr> </table> <table width="100%" border="1"> <tr> <td> <center><b>SrNo</b></center></td> <td> <center><b>Name </b></center></td> <td> <center><b>Level</b></center> </td> </tr> <?php include("database.php"); //include("auth.php"); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myst", $con); $result=mysql_query("SELECT * FROM members ORDER BY level"); $srno=1; while($srno<=5) { $row=mysql_fetch_array($result); print "<tr>"; print "<td>"; print "<center>"; print $srno; print "</center>"; print "</td>"; print "<td>"; print "<center>"; print $row['login']; print "</center>"; print "</td>"; print "<td>"; print "<center>"; print " ".$row['level']; print "</center>"; print "</td>"; print "</tr>"; $srno++; } mysql_close($con); ?> </table> <p> </p> <p> </p> </div> </body> </html> <?php } else { header("Location:welcome.php"); } ?> This is my complete code.I know it is in a lot of mess because i cudnt get my css to work properly so everything is in html.It all works fine except that i get the links to all the stages unconditionally. <a href="welcome.php">1</a>..<?php if($x>=2){?><a href="right.php">2</a>..<?php } if($x>=3){?><a href="code3.php">3</a><?}?>..4..5..6..7..8..9..10..11..12..13..14..15..16..17 ..18..19..20..21..22..23..24..25..26..27..28..29..30..Want more???? </td> </tr> </table> </div> This is the part where i am trying to do that.It does not work.I also update the level only if his level is less than the current level.I know it is difficult to go through such a messy code to find the bug...bt any help will b appreciated!!! Quote Link to comment https://forums.phpfreaks.com/topic/138887-help/ Share on other sites More sharing options...
fierdor Posted December 30, 2008 Author Share Posted December 30, 2008 Can the variables like $x be used globally?? I tried defining dem again in every php loop....Bt still no result! Quote Link to comment https://forums.phpfreaks.com/topic/138887-help/#findComment-726321 Share on other sites More sharing options...
ober Posted December 30, 2008 Share Posted December 30, 2008 $x can be used globally within the page, but not across pages. The information needs to be passed via URL or via SESSION variable. I guess the question is if you are allowing them to go back or only go forward? If they can go back and it seems like they can based on your code, I would do this: for($i=1;$i<$_GET['page'];$i++) echo "<a href=\"code$i.php\">$i..</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/138887-help/#findComment-726343 Share on other sites More sharing options...
fierdor Posted January 2, 2009 Author Share Posted January 2, 2009 Now is $_GET['page'] a standard library function??What value does it return?Sorry i am a newbie!! Quote Link to comment https://forums.phpfreaks.com/topic/138887-help/#findComment-727837 Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 You been told mate, The $_GET[''] command, let you get the variable/contents from the url. example. my_blody_website.com?name=redarrow so $_GET['name'] <<< holds redarrow. you can add more aswell my_blody_website.com?name=redarrow&surname=redarrow as you can see $_GET['name'] is redaarow and $_GET['surname'] is redarrow so it goes like this web_site_name.com then ? then a condition name=name then a & you can also use variables in the url $username="redarrow"; $surname="redarrow"; web_site_name.com?username=$username&surname=$surname good luck. Quote Link to comment https://forums.phpfreaks.com/topic/138887-help/#findComment-727842 Share on other sites More sharing options...
fierdor Posted January 2, 2009 Author Share Posted January 2, 2009 Then that is not the optimum solution to my problem because I dont want to do that through my url... Anyways I found the problem...So if anyone's interested: I was using $x only instead of $x['level']......!!!!!!!! Such a silly mistake...Nd I was thinking i was going logically wrong for 2 days...Damn!!!!! Anywayz Thanx a lot for the tut on $_GET['']; Quote Link to comment https://forums.phpfreaks.com/topic/138887-help/#findComment-727860 Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 Your welcome, Using sessions is safer then the get[''] i say. if you continue to use get on url's then i advise you to look up mod_rewrite. or a encrypting solution to hide url info. Quote Link to comment https://forums.phpfreaks.com/topic/138887-help/#findComment-727863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.