Xtremer360 Posted November 29, 2010 Share Posted November 29, 2010 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); } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 29, 2010 Share Posted November 29, 2010 = is the assignment operator. == is the equality operator. Use == for your comparison. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 29, 2010 Author Share Posted November 29, 2010 Hmm thank you I tried that and I'm NOW with the "==" for the comparison is there any such problems with my code now to not make it work at all. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 29, 2010 Share Posted November 29, 2010 for starters, i would follow every mysqli_query() with a check to see if the query worked or not via mysqli_error() Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 29, 2010 Author Share Posted November 29, 2010 I'm looking no the php.net website under procedural method and trying to grasp it. Would this be the correct synatx? mysqli_query($dbc, $query1) or mysqli_error($dbc); Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 29, 2010 Share Posted November 29, 2010 i would use: mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.