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); } ?> Link to comment https://forums.phpfreaks.com/topic/220176-if-statement-trouble/ 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. Link to comment https://forums.phpfreaks.com/topic/220176-if-statement-trouble/#findComment-1141109 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. Link to comment https://forums.phpfreaks.com/topic/220176-if-statement-trouble/#findComment-1141113 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() Link to comment https://forums.phpfreaks.com/topic/220176-if-statement-trouble/#findComment-1141115 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); Link to comment https://forums.phpfreaks.com/topic/220176-if-statement-trouble/#findComment-1141124 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)); Link to comment https://forums.phpfreaks.com/topic/220176-if-statement-trouble/#findComment-1141129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.