PHP - MySQL Fail


Posted on 16th Feb 2014 07:03 pm by admin

My PHP code will only execute the first part of my code...

Code: <?php

session_start();

?>

<html>

<head>

<title> Create a Character</title>

<style type="text/css">

body{

background-color: #000;

font-family: Arial, Tahoma;

font-size: .78em;

}

fieldset{

padding: 10px;

margin: 10px;

border: 1px solid #57626B;

width: 70%;

float: left;

}

legend{

background-color: #6A8CA5;

border: 1px solid #000;

padding: 5px;

}

input{

font-style: italic;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;

}


#tester{

background-color: #333;

margin: 0 auto;

padding: 10px;

width: 70%;

height: 80%;

}

#stats{

float: left;

width: 25%;

font-style: italic;

color: #000;

padding: 5px;

border: 1px dashed #999;

}

</style>



</head>

<body>

<div id="tester">



<?php

//Creation script designed by Cetanu of http://mythscape.freezoka.com and http://tehfreerpg.proboards.com

//This script is licensed by the Creative Commons for: Sharing, Attribution, Non-derivative, and non-commercial.

//You MUST leave these notices in for LEGAL use of this script. YOU MAY NOT EDIT THIS SCRIPT LEGALLY.

//For more: http://creativecommons.org/licenses/by-nc-nd/3.0/us/



if(empty($_SESSION['user_id'])){

die("<strong>You are not logged in. Please do so to access the RPG Sector.</strong>");

}

if(empty($_POST['cont'])){



echo " Time to create your character!<br/>

<form action='create.php' method='post'>

<fieldset>

<legend>Create Character for <strong>".$_SESSION['user_id']."</strong></i></u></legend>

<p>Please choose a species.</p>



<input type='radio' name='Species' id='pred' value='Predator'/>Predator (Yautja)<br/>

<input type='radio' name='Species' id='alien' value='Alien'/>Alien (Xenomorph)<br/>

<input type='radio' name='Species' id='human' value='Marine'/>Marine<br/> <br/>



<label for='name'>Character Name</label>

<input type='text' maxlength='25' id='name' name='name'/><br/>



<input type='hidden' maxlength='30' value='{$_SESSION['user_id']}' id='player' name='player' readonly='readonly'/><br/>





<input type='submit' name='cont' id='cont' value='Continue On'/>



</fieldset>

</form>";

}

echo "<br/>";

if(!empty($_POST['cont'])){

$species = $_POST['species'];
include "db.php";

if(empty($_POST['name']) || empty($_POST['Species'])){

echo "<script>document.write('You must input a species and a name!'); setTimeout("window.location.reload()", 350);</script>";

}



if ($species== "Predator" || "Alien" || "Marine" && !empty($_POST['name'])){


mysql_query("INSERT INTO rpg (name, species, player) VALUES ('{$_POST['name']}' , '{$_POST['Species']}' , '{$_POST['player']}')")

or die(mysql_error());
}


elseif($species=="Predator"){

mysql_query("UPDATE rpg SET max_health=25, health=25, attack=25, defense=25, honor=20 WHERE player='{$_POST['player']}')");

}

elseif($species=="Alien"){

mysql_query("UPDATE rpg SET health=20, max_health=20, attack=20 , defense=20 , stealth=20 WHERE player='{$_POST['player']}");

}

elseif($species=="Marine"){

mysql_query("UPDATE rpg SET health=15, max_health=15 , attack=20 , defense=20 , melee=20 WHERE player='{$_POST['player']}");

}

else{

echo "Invalid Species. Try again!";

}
mysql_query("INSERT INTO bank (player , amount) VALUES('{$_SESSION['user_id']}' , 5)");



header('Location: statadd.php');




}



?>





</div>





</body>



</html>
The part starts here...When it gets to the three elseif statements, they are the only things that won't execute. Everything else works. I don't get errors.
Code: <?php

if(!empty($_POST['cont'])){

$species = $_POST['species'];
include "db.php";

if(empty($_POST['name']) || empty($_POST['Species'])){

echo "<script>document.write('You must input a species and a name!'); setTimeout("window.location.reload()", 350);</script>";

}



if ($species== "Predator" || "Alien" || "Marine" && !empty($_POST['name'])){


mysql_query("INSERT INTO rpg (name, species, player) VALUES ('{$_POST['name']}' , '{$_POST['Species']}' , '{$_POST['player']}')")

or die(mysql_error());
}


elseif($species=="Predator"){

mysql_query("UPDATE rpg SET max_health=25, health=25, attack=25, defense=25, honor=20 WHERE player='{$_POST['player']}')");

}

elseif($species=="Alien"){

mysql_query("UPDATE rpg SET health=20, max_health=20, attack=20 , defense=20 , stealth=20 WHERE player='{$_POST['player']}");

}

elseif($species=="Marine"){

mysql_query("UPDATE rpg SET health=15, max_health=15 , attack=20 , defense=20 , melee=20 WHERE player='{$_POST['player']}");

}

else{

echo "Invalid Species. Try again!";

}
mysql_query("INSERT INTO bank (player , amount) VALUES('{$_SESSION['user_id']}' , 5)");



header('Location: statadd.php');




}
?>

No comments posted yet

Your Answer:

Login to answer
157 Like 10 Dislike
Previous forums Next forums
Other forums

php code to accept and delete incoming data
Using following HTML Code please show me how to write PHP code to accept and delete the incoming dat

asp authentication problem
Hello all, I want to use the asp authentication (from asp.net configuration) in my web site. there

Unable to display contents in Second Drop Down Box
Hi All,

What I am trying to do is 2 dependent drop down boxes and when user selects su

mail() problem
Hi Guys,

I've set up a contact email form. It sends the information fine, but it sends it to

Libraries in C++
Hi all,

I have two libraries. one is based targeted on linux platform and uses another li

Ajax Error since Upgrading to 3.5
Ever since upgrading my site to .NET 3.5 (I needed LINQ), I've been getting this annoying error on o

Appending GET data with form submition
Okay, what I'm trying to do is to use a form to append an already existing GET data string.

I

Extract specific information from a PHP Multidimensional Array
Howdy! I've racked my brain over this for 24 hours now. I think it's time I asked for help. I'm lear

Getting Subdomain Name With PHP?
I want to grab the subdomain name with PHP so I can generate database queries.

for example my

Extra fields in main body and php required.
I'm new to PHP so please be gentle. I have a little php script below that works well.
The &quo

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash