Jump to content

Help with code, isset etc


percox

Recommended Posts

Ok so, I am fairly new to PHP and starting to work on a Control Panel for our game. I have created a system where you can have 3 characters in the game. Anyway you create the characters in the Control Panel. When registering a new character you will pick which slot you want the character to go in. YOu have a choice out of Slot 1, Slot 2 or Slot 3... However if one of the slot has anything other than NONE in it. Then you are not able to use that slot.

 

So i gave it this attempt. Anyway it adds the bottom query, to the players table. But it does not add the query to the accounts table.... Updating your chosen slot from NONE to whatever name you chosen... Anyone able to point me in a good direction of why not?

 

<div id="content">
<?
    if (isset($_POST['add']))
    {
        if ($_POST['slot'] == '' || $_POST['name'] == '' || $_POST['age'] == '' || $_POST['gender'] == '' || $_POST['skin'] == '')
        {
            ?>
            <font color="#FF0014"><img src="images/validation.png"><B>Please fill in all fields to immigrate.</B></font><br /><a href="index.php?select=immigration">- Try again -</a>
            <?
                return false;
        }
        
        if ($_POST['slot'] == '1' && $_SESSION['player1'] != 'None')
        {
            ?>
            <font color="#FF0014"><img src="images/validation.png"><B>It seems that Character Slot is already being used..</B></font><br /><a href="index.php?select=immigration">- Try again -</a>
            <?
                return false;
        }
        else 
        {
            $dbs = mysql_query('SELECT ID FROM accounts WHERE LOWER(fusername) = LOWER("'.mysql_real_escape_string($_SESSION['name']).'") LIMIT 1');  
            if (mysql_num_rows($dbs) == 0)
            { 
                mysql_query('UPDATE `accounts` SET `player1` =  '.$_POST['name'].' WHERE `accounts`.`fusername` ='.$_SESSION['name'].' LIMIT 1');  
            }                                                                                
        }
        
        if ($_POST['slot'] == '2' && $_SESSION['player1'] != 'None')
        {
            ?>
            <font color="#FF0014"><img src="images/validation.png"><B>It seems that Character Slot is already being used..</B></font><br /><a href="index.php?select=immigration">- Try again -</a>
            <?
                return false;
        }
        else 
        {
            $dbss = mysql_query('SELECT ID FROM accounts WHERE LOWER(fusername) = LOWER("'.mysql_real_escape_string($_SESSION['name']).'") LIMIT 1');  
            if (mysql_num_rows($dbss) == 0)
            { 
                mysql_query('UPDATE `accounts` SET `player2` =  '.$_POST['name'].' WHERE `accounts`.`fusername` ='.$_SESSION['name'].' LIMIT 1');
            }                                                                                
        }
        
        if ($_POST['slot'] == '3' && $_SESSION['player1'] != 'None')
        {
            ?>
            <font color="#FF0014"><img src="images/validation.png"><B>It seems that Character Slot is already being used..</B></font><br /><a href="index.php?select=immigration">- Try again -</a>
            <?
                return false;
        }
        else 
        {
            $dbsss = mysql_query('SELECT ID FROM accounts WHERE LOWER(fusername) = LOWER("'.mysql_real_escape_string($_SESSION['name']).'") LIMIT 1');  
            if (mysql_num_rows($dbsss) == 0)
            { 
                mysql_query('UPDATE `accounts` SET `player3` =  '.$_POST['name'].' WHERE `accounts`.`fusername` ='.$_SESSION['name'].' LIMIT 1'); 
            }                                                                                
        }
        
        $db = mysql_query('SELECT ID FROM accounts WHERE LOWER(fusername) = LOWER("'.mysql_real_escape_string($_SESSION['name']).'") LIMIT 1');  
        if (mysql_num_rows($db) == 0)
        {
            $_POST['name'] = addslashes($_POST['name']);
            $_POST['age'] = addslashes($_POST['age']); 
            mysql_query('UPDATE `serverstats` SET `characters`=characters+1 WHERE id = 1');
            mysql_query('INSERT INTO players (Username, Age, Sex, Skin) VALUES ("'.mysql_real_escape_string($_POST['name']).'","'.mysql_real_escape_string($_POST['age']).'","'.mysql_real_escape_string($_POST['gender']).'","'.mysql_real_escape_string($_POST['skin']).'")');                  
            echo "
            <br /><br /><b><center><h2>Congratulations on Immigration</h2></center>
            <br />
            <br />".$_POST['name']." has now moved into San Fierro to start a new life.
            <br /> ".$_POST['name']." is ".$_POST['age']." years young.<br />
            You have chosen Skin ".$_POST['skin']." to immigrate with and told us that your sex is ".$_POST['gender']." (0 = Male) (1 = Female) <br />
            Good Luck!
            <br /><br />
            <br />
            <br />
            </b>";
            return true;
        }
        else
        {
            echo '<font color="#FF0014"><B><img src="images/validation.png">Sorry this Account is already registered.Please choose another one</B></font><br /><a href="index.php?select=register">- Try again -</a>';
                return false;
        }
} 
    
    if ($_SESSION['loggedin'] == true) 
    {
            echo '<h2> San Fierro Immigration Department</h2> <br />
            <div id="immigration">
            <b>Account Name:</b> '.$_SESSION['Name'].' 
            </div>
            <br /> 
            <div id="immigration">
            <b>Character 1: </b>'; if($_SESSION['player1'] == "None") {echo 'No Character';} else { echo $_SESSION['player1'];}
            echo '<br /><b>Character 2: </b>'; if($_SESSION['player2'] == "None") {echo 'No Character';} else { echo $_SESSION['player2'];}
            echo '<br /><b>Character 3: </b>'; if($_SESSION['player3'] == "None") {echo 'No Character';} else { echo $_SESSION['player3'];}
            echo '</div> <br />';
            
            echo '<div id="immigration"><center><h2> San Fierro Imigration Application Services </h2> <br />

            <form method=post>
            <table>
            <tr>
            <td>Character Slot:</td>
             <td><input class="textinput" type=text name="slot"></td>
            </tr>
            <tr>
            <td>Name:</td>
             <td><input class="textinput" type=text name="name"></td>
            </tr>
            <tr>
            <td>Age:</td>
            <td><input class="textinput" type=text name="age"></td>
            </tr>
            <tr>
             <td>Gender: </td>
             <td><input class="textinput" type=text name="gender"></td>
            </tr>
            <tr>
             <td>Skin: </td>
             <td><input class="textinput" type=text name="skin"></td>
            </tr> 
            <tr></tr>
            <tr><td></td><td><br /><input class="button" type=submit value="Apply Now!" name="add"></td></tr>
            </table>
            </form></center> </div> ';
            
    }                         
    else
    { 
        echo 'Login First';             
    }
?>
</div>

 

See I wernt sure if you could put the queries in the isset, but i dunno, im confused now.

Link to comment
https://forums.phpfreaks.com/topic/196368-help-with-code-isset-etc/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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