Page 1 of 1

Quests help

Posted: Tue Aug 16, 2011 7:16 pm
by dust1031
so i started coding a Quest system for my game, i set up the DB and coded the quest, and set up my 1st quest but when i go to Quests nothing comes up so its having trouble getting the information from the DB. Can someone please take a look.

quests.php

Code: Select all

<?php
include_once 'connect.php';
session_start();

include_once 'logo.php';
?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>

<?php
$bypass = 0;
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$id=$playerinfo3['id'];

 $questname = $playerinfo3['name'];
$level = $playerinfo3['level'];

$questinfo="SELECT * from quests where name='$questname'";
$questinfo2=mysql_query($questinfo) or die("could not  select quests!");
$questinfo3=mysql_fetch_array($questinfo2);

print "<center><h3>Quests</h3></center>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $selectquests="SELECT * from quests where pid='$id'";
      $selectquests2=mysql_query($selectquests) or die("could not select quests");
      print "<table border='1' bordercolor='black' bgcolor='#ffffff' >";
      print "<tr><td>Name<font color='ffffff'>_________________</td><td>Experience<font color='ffffff'>_</td><td>Gold<font color='ffffff'>_</td></tr>";
      while($selectquests3=mysql_fetch_array($selectquests2))

	   print "<tr><td>$selectquests3[name]</td><td>$selectquests3[exp]</td><td>$selectquests3[gold]</td></tr>";
this is what comes up when i click the quests link on the game

Image



this is what my quests DB looks like
Image

can someone please help me.
i hope the pictures uploaded right

Re: Quests help

Posted: Tue Aug 16, 2011 7:17 pm
by Xaleph
Your picture did not upload right.. :)

Re: Quests help

Posted: Tue Aug 16, 2011 7:26 pm
by dust1031
Image

Image


did this work? i uploaded it via photobucket

Re: Quests help

Posted: Tue Aug 16, 2011 7:28 pm
by dust1031
sorry for asking u to do this, but i see it still didnt upload right. but if u right click and click open image in new tab it will open correctly

Re: Quests help

Posted: Tue Aug 16, 2011 7:38 pm
by Jackolantern
It looks like you are saving the player's name, and then looking for a quest that has that same name:

Code: Select all

$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$id=$playerinfo3['id'];

$questname = $playerinfo3['name']; //why is this being saved into $questname?
$level = $playerinfo3['level'];

$questinfo="SELECT * from quests where name='$questname'"; //using the player name to find a similarly named quest
$questinfo2=mysql_query($questinfo) or die("could not  select quests!");
$questinfo3=mysql_fetch_array($questinfo2);
And looking at the quest table in your db, it doesn't look like any quest is going to have the same name as a player. That is likely why no quests are going to be found, since the name of your quest is "Starting out small".

Re: Quests help

Posted: Tue Aug 16, 2011 7:55 pm
by dust1031
ok i changed where it has $questname = $playerinfo3['name']; to $questname = $questinfo3['name']; but now it comes up an error that says Notice: Undefined variable: questinfo3 in C:\wamp\www\tutorial\quests.php on line 31

Re: Quests help

Posted: Tue Aug 16, 2011 8:38 pm
by 62896dude
$questname has to come after you define $questinfo3 :)

Re: Quests help

Posted: Tue Aug 16, 2011 8:39 pm
by Jackolantern
Did you change this line:

Code: Select all

$questname = $playerinfo3['name']; //why is this being saved into $questname?
$level = $playerinfo3['level'];
...to this?

Code: Select all

$questname = $questinfo3['name']; //why is this being saved into $questname?
$level = $playerinfo3['level'];
That isn't going to work because you actually run the quest info query and make the $questinfo3 variable below this in the code, which means it doesn't exist at the point you are trying to use it.

I think you are going to have to reconsider how you are making your quest system so far. Maybe try using the player's level to find the quest instead of the quest name? Something like this will work in that case:

Code: Select all

$questinfo="SELECT * from quests where level <= $level limit 1";
Or you will need to do something else to get the name of the quest. What that something else is depends on how you want players to find quests.

Re: Quests help

Posted: Tue Aug 16, 2011 8:48 pm
by claymore88
you could select name from quest. and echo the column with row. and then make a quest info page and echo the rewards etc

Re: Quests help

Posted: Mon Sep 05, 2011 8:55 pm
by Andrew
Hey could you please tell me how the database should look like in text since i can't open your pictures


Thanks,

Andrew