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
https://forums.phpfreaks.com/topic/47098-going-insane-need-expert-help/
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

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]

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.

Archived

This topic is now archived and is closed to further replies.

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