I’ve been working on a PHP game, and it’s doing alright so far. You can choose from one of 4 types of people. They each have different stats.
I added their stats using if() statements. Take a look. The first section is just the form, the next is the actual code. I took out my database username and password, so don’t say that’s the problem.
[code]<?php
session_start();
if(isset($_SESSION[‘email’])) {
}
$con = mysql_connect(‘localhost’,‘bklyn’);
if(!$con) {
die('Error connecting to localhost: ’ . mysql_error());
}
$db = mysql_select_db(‘socialdb’,$con);
if(!$db) {
die('Error connecting to database: ’ . mysql_error());
}
?>
Knight Mage Assassin Barbarian
[/code]
And the PHP…
[php]<?php
session_start();
if(isset($_SESSION[‘email’])) {
}
$name = $_POST[‘name’];
$class = $_POST[‘class’];
$email = $_SESSION[‘email’];
$one = “SELECT * FROM rpg WHERE email=’$email’ AND class=’$class’”;
$two = mysql_query($one);
if($two == 2) {
echo “You already have two heroes of this class. Go <a href=“newhero.php”>back to make a new hero.”;
}
if($class == “knight”) {
$strength = 10;
$specialstrength = 5;
$defense = 9;
$specialdefense = 7;
$accuracy = 8;
$move1 = “Swing your sword”;
$move2 = “Bang heads (your armor is so tough, you take no damage)”;
$move3 = “Poison or burn enemy (40 energy)”;
}
if($class == “mage”) {
$strength = 5;
$specialstrength = 15;
$defense = 7;
$specialdefense = 10;
$accuracy = 8;
$move1 = “Bash enemy with wand”;
$move2 = “Dangerous gust of wind (30 energy)”;
$move3 = “Small fireball, 10% chance of burn (25 energy)”;
}
if($class == “assassin”) {
$strength = 15;
$specialstrength = 5;
$defense = 8;
$specialdefense = 5;
$accuracy = 20;
$move1 = “Tackle”;
$move2 = “Swing secret sword”;
$move3 = “Restore health (45 energy)”;
}
if($class == “barbarian”) {
$strength = 18;
$specialstrength = 10;
$defense = 5;
$specialdefense = 5;
$accuracy = 8;
$move1 = “Crazily swing arms”;
$move2 = “Bite”;
$move3 = “Burp (75% chance of poison) (30 energy)”;
}
$sql = “INSERT INTO rpg (Name, Level, XP, Health, Email, Gold, Energy, Class, Strength, SpecialStrength, Defense, SpecialDefense, Accuracy, Move1, Move2, Move3) VALUES ($name, 1, 0, 100, $email, 1000, 50, $class, $strength, $specialstrength, $defense, $specialdefense, $accuracy, $move1, $move2, $move3)”;
if(!$sql) {
die(mysql_error());
}
else {
echo “Hero successfully created. <a href=“heroes.php”>Click here to return to the hero page.”;
}
?>[/php]
The error is saying that all of the variables holding stats ($strength, $defense, $accuracy, so on) are undefined. I clearly defined them. Help? Thank you!