Jump to content

If statement trouble


Xtremer360

Recommended Posts

I'm trying to figure out why my entire if statement is not working properly. What is happening when I run my form is that it puts it into the first if statement regardless of what the value of $style is and I don't know why. The other parts of the for submission works BUT my if statement. And inside of firebug it is passing the RIGHT post data so it has the correct value for style each time.

 

<?php

// Include the database page
require ('../inc/dbconfig.php');

if (isset($_POST['submitcharacter'])) {
    $charactername = mysqli_real_escape_string($dbc, $_POST['charactername']);
    $charactershortname = mysqli_real_escape_string($dbc, $_POST['charactershortname']);
    $sortorder = mysqli_real_escape_string($dbc, $_POST['sortorder']);
    $style = mysqli_real_escape_string($dbc, $_POST['style']);
    $status = mysqli_real_escape_string($dbc, $_POST['status']);
    $alignment = mysqli_real_escape_string($dbc, $_POST['alignment']);
    $division = mysqli_real_escape_string($dbc, $_POST['division']);

    $query = "INSERT INTO `characters` (charactername, charactershortname, status_id, style_id, division_id, alignment_id, sortorder, creator_id, datecreated) VALUES ('$charactername','$charactershortname','$status','$style','$division', '$alignment', '$sortorder', 1, NOW())";
    mysqli_query($dbc, $query);
    $query_id = mysqli_insert_id($dbc); 
    $query1 = "INSERT INTO `allies` (character_id) VALUES (".$query_id.")";
    mysqli_query($dbc, $query1);  
    $query2 = "INSERT INTO `rivals` (character_id) VALUES (".$query_id.")";
    mysqli_query($dbc, $query2);  
    if ($style = 1) {
        $query3 = "INSERT INTO `singles` (character_id) VALUES (".$query_id.")";
        mysqli_query($dbc, $query3);  
     } elseif ($style = 2) {
        $query4 = "INSERT INTO `tagteams` (character_id) VALUES (".$query_id.")";
        mysqli_query($dbc, $query4);
     } elseif ($style = 3) {       
        $query5 = "INSERT INTO `managers` (character_id) VALUES (".$query_id.")";
        mysqli_query($dbc, $query5);        }       
     } elseif ($style = 4) {
        $query6 = "INSERT INTO `stables` (character_id) VALUES (".$query_id.")";
        mysqli_query($dbc, $query6);  
     } elseif ($style = 5) {
        $query7 = "INSERT INTO `referees` (character_id) VALUES (".$query_id.")";
        mysqli_query($dbc, $query7);  
     } else {
        $query8 = "INSERT INTO `staff` (character_id) VALUES (".$query_id.")";
        mysqli_query($dbc, $query8);   
     }
        
?>

Link to comment
https://forums.phpfreaks.com/topic/220176-if-statement-trouble/
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.