Page 1 of 3

Project Z Help thread.

Posted: Mon Jul 12, 2010 5:02 pm
by Corinthius
Evening everyone! :)
Thanks to halls I've been able to continue with a project I started in high-school, it was more motivation than anything as I get a real sense of similarity in situation between us. I've coded quite a few minor things before, and have been looking for a community like this one to further the development and maybe pick up a few friends along the way!

This thread, I was hoping anyway, could be used to help me further on with my project, I tend to run into small, silly mistakes when i'm coding and it's often just easier to continue with other features instead of spending the day figuring the error out. (Time is the most evil thing for a programmer).
Any help would be extremely appreciated, I plan to stick around and see who i can help out on here too - so don't hesitate to ask :)

This is just an introductory post, below i'll be posting little errors.
Thanks ~ Corinthius.

Re: Project Z Help thread.

Posted: Mon Jul 12, 2010 5:11 pm
by Corinthius
My first error while modifying Forsaken Sanctum came when I tried to add in a little user validation as such.
The situation is; I want to enable a kind of community system where towns develop, mayors, councils, officials and so on - For that reason I don't want more than one of certain buildings , for example a town hall ~

I have tried to do a simple calculation to stop users from doing this, and I have tried many things, but with that I haven't had any luck! I hope someone here can point out the wrongs, or even just improvements to the code (cleaner is better y'know?) - Thanks! :D

Code: Select all

$numb="SELECT townhall from housing where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
        $numb2=mysql_query($numb) or die("Could not select information");
    
	if ($numb2 == 1)
	{
	echo "There is already a town hall established here!";
	echo "<center><br><A href='build.php'>Go Back";
	exit;
	}
Now for a little background information on the database -
I edited the "housing" table where it has "1" or "0" for certain types of buildings - To allow for a townhall amongst the other buildings. Once a town hall is built it gives that location a "1" for town hall.

Above in the code, it's supposed to be;
if townhall = 1 then { display: You can't have a town hall, because there is already one established" };


Of course, the problem is that it doesn't work.
What DOES work is; the database updates to add "1" for the location, the town hall is built and usable.
However, the use is able to build 2 of them. I can't seem to fix this, if anybody knows a solution I would be very great full! :)

Corinthius.

Re: Project Z Help thread.

Posted: Mon Jul 12, 2010 5:28 pm
by Jackolantern
I believe this is because you are testing a variable that contains a raw MySQL result resource object. Since that will never equal the value 1, you need turn the resource into an array and compare the correct field:

Code: Select all

$numb="SELECT townhall from housing where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
        $numb2=mysql_query($numb) or die("Could not select information");
        $numb3 = mysql_fetch_assoc($numb2);
    
   if ($numb3['townhall'] == 1)
   {
   echo "There is already a town hall established here!";
   echo "<center><br><A href='build.php'>Go Back";
   exit;
   }

Re: Project Z Help thread.

Posted: Mon Jul 12, 2010 6:52 pm
by Corinthius
Thank you for replying! :D
Unfortunately, it still isn't working - I had previously tried that (Not sure why I didn't change it back) - it seems to be adding in town-hall fields to the "housing" table where the "townhall" value is 1 for each.
The map location co-ordinates are 1,1 and are correct, but for some reason...it's still not working.

Thank you for your help!

**EDIT**
I'm using WAMP server, with error display turned on, however it appears that nothing is in-need of declaration or missing any defined values ...
A pesky problem in-deed.

Re: Project Z Help thread.

Posted: Mon Jul 12, 2010 7:04 pm
by Jackolantern
Comment out the IF structure and just echo out the value stored in the field to see what it is. Also add some more fields to the query and echo those out to ensure you are pulling up the right record. Do the same thing wherever you think there could be an issue, or wherever you have just added in some new logic. If you are hitting on the right field in the database and pulling up the right value, the logic error is happening somewhere else.

Re: Project Z Help thread.

Posted: Tue Jul 13, 2010 2:04 am
by hallsofvallhalla
numb2 will never == 1.

You need to turn this into a array like all of my queries then check the field in the table if it is equal to 1.

Re: Project Z Help thread.

Posted: Tue Jul 13, 2010 3:39 am
by Jackolantern
hallsofvallhalla wrote:numb2 will never == 1.

You need to turn this into a array like all of my queries then check the field in the table if it is equal to 1.
Just like I said :D :D :D

He said he is still having trouble, though. I don't know what else is wrong with it based on the code we were provided. Maybe the OP can post the rest of the script, or just work on doing some logic debugging, because I don't see anything else wrong with the query logic. Maybe there is something in the database structure not jiving with the logic here.

Re: Project Z Help thread.

Posted: Tue Jul 13, 2010 7:36 am
by Rastan
if ($numb3['townhall'] == 1)

For me if I have to do that type of thing I have to do it like

if ($numb3['townhall'] == '1')

I actually had trouble one night for a while and once I put those around the number it stopped. I thought originally that it didn't have to be that way but I'm still fairly new at all the rules here lol. I did however just take an almost identical check from my game I'm making that works take away the quotes on the number and broke it to make sure I'm not crazy.

Re: Project Z Help thread.

Posted: Tue Jul 13, 2010 8:15 am
by Jackolantern
Are you sure that field is not set up as a char or varchar value? Because if it is being stored as an integer, it should work with 1, and not '1'.

Re: Project Z Help thread.

Posted: Tue Jul 13, 2010 8:26 am
by Rastan
Yeah the field that the one I changed is set to smallint. if i set something = to 1 it works fine with no ' ' but it seems if I want to check something from the DB say I'm looking for a 1 and I don't use the ' ' it won't check it for me. it'll echo out to be 1 still tho which should be correct. I'm def not one who knows all the rules I just trial and error till it works lol