Jump to content

Going Insane - need expert help!!


widget

Recommended Posts

Hi, I am running a virtual pet style site.

Reason: Learning php and what better way to do it :)

 

Anyway when a user buys a book to read to its pet, its intelligence rating goes up. What Im trying to do is make it so that if they have read the book already, they cannot read it again.

 

I've managed to create a new database table and have the information writing to it but I cant seem to get the rest of it working.

 

Heres the code so far.

 

if ($find_item2[item_type] == "intel_inc")
{	
$getread = fetch("SELECT * FROM read2 WHERE pet_id = '$use_on' AND item_id = '$find_item2[id]' AND game = '$game'");



if  (!$getread);
{

		mysql_query("INSERT INTO read2 (item_id,pet_id,game) VALUES ('$find_item2[id]','$use_on','$game')");

			$newLevel = $getPetInfo[intelligence]+$find_item2[magic_num];

			mysql_query("UPDATE user_pets2 SET intelligence=$newLevel WHERE id = '$use_on' AND game = '$game'");
   
			$effect = "<p>$getPetInfo[name] really liked that book!</p>";

}
    if ($getread);
{
		$effect = "<b>Sorry, $getPetInfo[name] has read this book already</b>";
}

}

 

If i try an if  then an else I get errors. I really need some help here.

 

If you know a great tutorial or can help me with the code please post.

Link to comment
Share on other sites

You shouldn't have semi-colons after the if/else clause:

 

<?php
if ($find_item2[item_type] == "intel_inc")
{
        $q = "SELECT * FROM read2 WHERE pet_id = '$use_on' AND item_id = '" . $find_item2['id'] . "' AND game = '$game'";
        $rs = mysql_query($q) or die("Problem with the query <pre>$q</pre><br>" . mysql_error());
        $getread = (mysql_num_rows > 0)?true:false;
        if  (!$getread) {
     $newLevel = $getPetInfo[intelligence]+$find_item2[magic_num];
     $q = "INSERT INTO read2 (item_id,pet_id,game, intelligence) VALUES ('$find_item2[id]','$use_on','$game','$newLevel')";
             $rs = mysql_query($q) or die("Problem with the query <pre>$q</pre><br>" . mysql_error());
     $effect = "<p>$getPetInfo[name] really liked that book!</p>";
        }
        else
     $effect = "<b>Sorry, $getPetInfo[name] has read this book already</b>";
}
?>

 

I also cleaned up your code a little...

 

Ken

Link to comment
Share on other sites

Thank you Ken, that looks fab and I'll try it now.

I have although managed to get it working by using this code (yours looks much better)

 

if ($find_item2[item_type] == "intel_inc")
{	
$getread = fetch("SELECT item_id FROM read2 WHERE pet_id = '$use_on'");

if ($getread[item_id] == "$find_item2[id]")
{
	$effect = "<b>Sorry, $getPetInfo[name] has read this book already</b>";
}
	   elseif ($getread[item_id] != "$find_item2[id]")
	{
		mysql_query("INSERT INTO read2 (item_id,pet_id,game) VALUES ('$find_item2[id]','$use_on','$game')");
		$newLevel = $getPetInfo[intelligence]+$find_item2[magic_num];
		mysql_query("UPDATE user_pets2 SET intelligence=$newLevel WHERE id = '$use_on' AND game = '$game'");
   			$effect = "<p>$getPetInfo[name] really liked that book!</p>";
	}
}
[code]

[/code]

Link to comment
Share on other sites

Ok it was working and now for some reason its not!!!!

 

I havent changed anything, this is so frustrating.

 

We both know that isn't possible. Something is different!! Post the code that isn't working. Explain what it's not doing that it did before and vice versa. Be certain that you uploaded any edited versions to the same folder/same server, etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.