•
•
•
•
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
![]() |
•
•
Join Date: Dec 2007
Posts: 71
Reputation:
Rep Power: 1
Solved Threads: 0
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!
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;
}
?>•
•
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 771
Reputation:
Rep Power: 2
Solved Threads: 63
Try this and if the answer still isn't apparent, post the results.
php Syntax (Toggle Plain Text)
<?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']); print_r($form); echo "<br />" . $pet_species; ?>
“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
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
activation age amd avatar blogs blue gene chips code combo dani daniweb database development dos economy energy enterprise hardware ibm ibm. news intel ibm it key linux medicine memory microsoft news open source openoffice pc product programming ps3 recession red hat remote working rss russia serial sun supercomputer supercomputing tags technology trends ubuntu vista working x86
- CHECKBOX VAILDATION CODE not working (PHP)
- Does this code working after changing environment? (VB.NET)
- javascript code not working in firefox (JavaScript / DHTML / AJAX)
- I would liike to multiply two matrices but my code is not working..help me out! (C++)
- Problems launching java source code (serious newbie, sorry! :( ) (Java)
- this code isn't working...why..plz help (C++)
- Something wrong with my code, why Junk character appears? (C)
- Code not working for deleting recordfrom a file (Visual Basic 4 / 5 / 6)
- Need help with DirectX code (C)
Other Threads in the PHP Forum
- Previous Thread: directory functions not working
- Next Thread: what is wrong here....


Linear Mode