User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,018 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,712 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 150 | Replies: 1
Reply
Join Date: Dec 2007
Posts: 71
Reputation: justted is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
justted justted is offline Offline
Junior Poster in Training

PH code not working! :O(

  #1  
Jul 20th, 2008
Hello everyone,

I have been trying to get this piece of code to work and havent been able to see why it isnt working!

The code is a training school page for my virtual pet site in which members should be able to go and choose which pet they want to teach a particular attack or defense move too! There are certain different species. The admin control panal which allows you to add, edit and delete attacks works fine but whenever you go to the page and try to buy an attack or defense move the page comes up with the elseif snippet which is:

This Attack is not available for this species of pets.
Go Back


As you can see in the code below that is one of the PHP elseif commands! I cant see why it isnt letting me. It doesnt seem to be able to identify the pet species and so says you are not able to teach that pet a move.


Any ideas? Any help is much appreciated!


<?php
$rank_check = 1;
$page_title = "Training Center";
include "header.inc.php";
echo $openHTML;
print "<p align='center'><b>Training Center</b></p>";

If ($_POST['attack_selected'] == 'yes'){
$res1 = mysql_query("SELECT * FROM user_pets2 WHERE id='".$_POST['pet_id']."' AND owner = '$userid' AND adoption = '0' AND game = '$game'");
$pet = mysql_fetch_assoc($res1);
$res2 = mysql_query("SELECT * FROM attacks2 WHERE id='".$_POST['attack_id']."' AND game= '$game'");
$attack = mysql_fetch_assoc($res2);
$res3 = mysql_query("SELECT * FROM members2 WHERE id='$userid'");
$user = mysql_fetch_assoc($res3);
$res4 = mysql_query("SELECT id, name FROM pets2 WHERE id='".$pet['species']."'");
$pet_sp = mysql_fetch_assoc($res4);
$res5 = mysql_query("SELECT * FROM bought_attacks WHERE attack_id='".$attack['id']."' AND user_pet='".$pet['id']."'");
$num = mysql_num_rows($res5);


$form = explode(", ", $attack['learned_by']);
$pet_species = strtolower($pet_sp['name']);

if ($user['points'] < $attack['attack_price']){
	echo "<p align='center'>You don't have enough munny to buy this attack.<br><a href='training.php?game=$game'>Go Back</a></p>";
	exit;
}elseif(!in_array($pet_species, $form)){
	echo "<p align='center'>This Attack is not available for this species of pets.<br><a href='training.php?game=$game'>Go Back</a></p>";
	exit;
}elseif($attack['learn_at_level'] > $pet['level']){
	echo "<p align='center'>You pet's level is not enough to teach this attack.<br><a href='training.php?game=$game'>Go Back</a></p>";
	exit;
}elseif($num != 0){
	echo "<p align='center'>This pet has already learnt this attack.<br><a href='training.php?game=$game'>Go Back</a></p>";
	exit;
}else{
	$del = mysql_query("UPDATE members2 SET points='points-".$attack['attack_price']."' WHERE id='user_id'");
	$_at = $attack['id'];
	$_pet = $pet['id'];
	$ins = mysql_query("INSERT INTO bought_attacks VALUES ('$_at', '$_pet')") or die (mysql_error());
	echo "<p align='center'>".$attack['attack_name']." has been succesfully bought and teached to Your Pet.<br><a href='training.php?game=$game'>Go Back</a></p>";
	exit;
}


	
}else{
echo "<p><center>Here is list of all Attacks You can teach Your Pets. Each Attack is for specified pets.</p><center><table>";
$ret = "<form action='' method='post'><select name='attack_id'>";
$res = mysql_query("SELECT * FROM attacks2 WHERE attack_price <> 0 AND attack_price <> '' AND game= '$game'");
while ($row = mysql_fetch_assoc($res)){
	$ret .= "<option value=".$row['id'].">".$row['attack_name']." -- ".$row['do_what']." -- ".$row['attack_price']." munny</option>";
}
$ret .= "</select><br>Which Pet? <select name = 'pet_id'>";
$res = mysql_query("SELECT * FROM user_pets2 WHERE owner = '$userid' AND adoption = '0' AND game = '$game'");

while ($row = mysql_fetch_assoc($res)){
$ret .= "<option value=".$row['id'].">".$row['name']."</option>";	
	
}
$ret .= "</select><br><input type='hidden' name='attack_selected' value='yes'><input type='submit' name='submit' value='Learn new Attack'></form>" ;
echo $ret;
}








?>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 771
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 63
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Master Poster

Re: PH code not working! :O(

  #2  
Jul 21st, 2008
Try this and if the answer still isn't apparent, post the results.
  1. <?php
  2. $rank_check = 1;
  3. $page_title = "Training Center";
  4. include "header.inc.php";
  5. echo $openHTML;
  6. print "<p align='center'><b>Training Center</b></p>";
  7.  
  8. If ($_POST['attack_selected'] == 'yes'){
  9. $res1 = mysql_query("SELECT * FROM user_pets2 WHERE id='".$_POST['pet_id']."' AND owner = '$userid' AND adoption = '0' AND game = '$game'");
  10. $pet = mysql_fetch_assoc($res1);
  11. $res2 = mysql_query("SELECT * FROM attacks2 WHERE id='".$_POST['attack_id']."' AND game= '$game'");
  12. $attack = mysql_fetch_assoc($res2);
  13. $res3 = mysql_query("SELECT * FROM members2 WHERE id='$userid'");
  14. $user = mysql_fetch_assoc($res3);
  15. $res4 = mysql_query("SELECT id, name FROM pets2 WHERE id='".$pet['species']."'");
  16. $pet_sp = mysql_fetch_assoc($res4);
  17. $res5 = mysql_query("SELECT * FROM bought_attacks WHERE attack_id='".$attack['id']."' AND user_pet='".$pet['id']."'");
  18. $num = mysql_num_rows($res5);
  19.  
  20.  
  21. $form = explode(", ", $attack['learned_by']);
  22. $pet_species = strtolower($pet_sp['name']);
  23.  
  24. print_r($form);
  25. echo "<br />" . $pet_species;
  26. ?>
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 1:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC