Jump to content

Recommended Posts

Okay, here is my 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; 
}
#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 
if(!$_POST['cont']){

echo " Time to create your character!<br/> 
<form action='create.php' method='post'> 
<fieldset> 
<legend>Create Character for <u><i>YOU CAN USE MEMBER'S NAME HERE!!!</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' value='Enter Character Name Here' id='name' name='name'/><br/> 
<label for='player'>Your Name</label> 
<input type='text' maxlength='30' value='{$_SESSION['username']}' id='player' name='player' readonly='readonly'/><br/> 


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

</fieldset> 
</form>";
} 
?>
<br/> 
<?php 
if($_POST['cont']){ 

if($_POST['Species'] != "Alien" || "Predator" || "Marine"){
echo "You do not have the correct species. Try again. <a href=\"create.php\" title='Click to Reload'>Click to Reload Page</a>"; 
}

else{
include "db.php"; 
mysql_query("INSERT INTO rpg (name, species, player) VALUES ('{$_POST['name']}' , '{$_POST['Species']}' , '{$_POST['player']}')")
or die(mysql_error());  
echo "Success!";
}
}

?>


</div>  


</body> 

</html> 

 

 

In these lines:

<?php 
if($_POST['cont']){ 

if($_POST['Species'] != "Alien" || "Predator" || "Marine"){
echo "You do not have the correct species. Try again. <a href=\"create.php\" title='Click to Reload'>Click to Reload Page</a>"; 
}

else{
include "db.php"; 
mysql_query("INSERT INTO rpg (name, species, player) VALUES ('{$_POST['name']}' , '{$_POST['Species']}' , '{$_POST['player']}')")
or die(mysql_error());  
echo "Success!";
}
}

?>

 

I want to make sure that those sneaky people with Firebug don't mess with the choices. However, when I select an option that IS right it still gives me the error about having an incorrect species chosen. It used to work until I added in the stuff about inserting into PLAYER and using $_POST['player'] for the value.

 

 

Help? :shy:

 

EDIT: It also will not insert my data for some reason.

Link to comment
https://forums.phpfreaks.com/topic/171090-solved-simple-if-else-problem/
Share on other sites

In the IF you have to define each statement, you can't use OR operator to repeat them.

 

if($_POST['Species'] != 'Alien' || $_POST['Species'] != 'Predator' || $_POST['Species'] !=  'Marine'){

Or else it'd just appear as.. 'if("Preditor")' and that'd be invalid to parse.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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