indalecio Posted July 5, 2006 Share Posted July 5, 2006 This DOES use phpBB, but thats not the concern. I am trying to get this If / Else statement to read the $problem variable, but for some reason it just doesn't to, and it moves onto the item creation. I have tried this current setup, isset(), and !isset(). Any help is appreciated.[code]/////////////// Weapons /////////////// if ( $_POST['equipment_type'] == 'weapon' ) { if ( isset($_POST['submit']) ) { if ( !isset($_POST['weapon_name']) ) { $problem = '1'; $problem_statement = 'Your weapon did not have a name<br>'; } if ( !isset($_POST['weapon_type']) ) { $problem = '1'; $problem_statement = $problem_statement . 'Your weapon did not have a type<br>'; } if ( !isset($_POST['weapon_job1']) ) { $problem = '1'; $problem_statement = $problem_statement . 'Your weapon did not have a class<br>'; } if ( !isset($_POST['weapon_job1']) && isset($_POST['weapon_job2']) ) { $problem = '1'; $problem_statement = $problem_statement . 'There was a problem with the classes you chose.<br>'; } if ( !isset($_POST['weapon_job1']) && !isset($_POST['weapon_job2']) && isset($_POST['weapon_job3']) ) { $problem = '1'; $problem_statement = $problem_statement . 'There was a problem with the classes you chose.<br>'; } if ( !isset($_POST['weapon_dmg_low']) && !isset($_POST['weapon_dmg_hi']) ) { $problem = '1'; $problem_statement = $problem_statement . 'Your weapon is missing a damage parameter.<br>'; } if ( !isset($_POST['weapon_lvl']) ) { $problem = '1'; $problem_statement = $problem_statement . 'Your weapon is missing the level parameter.<br>'; } if ( !isset($_POST['weapon_cost']) ) { $problem = '1'; $problem_statement = $problem_statement . 'Your weapon is missing the cost parameter.<br>'; } if ( !isset($_POST['weapon_weight']) ) { $_POST['weapon_weight'] = '0'; } if ( !isset($_POST['weapon_def']) ) { $_POST['weapon_def'] = '0'; } if ($problem == '1') { if ( $_POST['weapon_hands'] == '1' ) { $template->set_filenames(array( 'body' => 'admin/weapon_add_one.tpl') ); $template->assign_vars(array( 'PROBLEM_STATEMENT' => $problem_statement ) ); } elseif ( $_POST['weapon_hands'] == '2' ) { $template->set_filenames(array( 'body' => 'admin/weapon_add_two.tpl') ); $template->assign_vars(array( 'PROBLEM_STATEMENT' => $problem_statement ) ); } } else { /**************************** * Insert weapon to database * *****************************/ $update = DATABASE INFO if (!$update) { message_die(GENERAL_MESSAGE, 'Your weapon could not be added.' ); } $success = TRUE; } } else { /************************ * Go to Add weapon Page * *************************/ if ( $_POST['weapon_hands'] == '1' ) { $template->set_filenames(array( 'body' => 'admin/weapon_add_one.tpl' ) ); } elseif ( $_POST['weapon_hands'] == '2' ) { $template->set_filenames(array( 'body' => 'admin/weapon_add_two.tpl' ) ); } $template->assign_vars(array( 'FORM_ACTION' => append_sid("admin_equipment.$phpEx") ) ); }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13707-running-if-else-argument-problems/ Share on other sites More sharing options...
Orio Posted July 5, 2006 Share Posted July 5, 2006 Try adding a semicolon after every if:if ( !isset($_POST['weapon_def']) ) {$_POST['weapon_def'] = '0';}[color=red][b];[/b][/color]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13707-running-if-else-argument-problems/#findComment-53230 Share on other sites More sharing options...
slipperyfish Posted July 5, 2006 Share Posted July 5, 2006 if that fails still, try putting the "equipment_type" into a variable be4 running the if-- but i myab e wrong in that. Quote Link to comment https://forums.phpfreaks.com/topic/13707-running-if-else-argument-problems/#findComment-53233 Share on other sites More sharing options...
heckenschutze Posted July 5, 2006 Share Posted July 5, 2006 Do you really need to quote your integers..., that could have something to do with your problem. Quote Link to comment https://forums.phpfreaks.com/topic/13707-running-if-else-argument-problems/#findComment-53275 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 First, the first answer about putting a semi-colon after the end curly bracket is incorrect.Next, copying the value to a temporary variable will not make any difference.How is your form set up? Are all of the posted fields you are testing text fields? If they are, then they will be set when your script is invoked when the form is submitted whether or not any data is entered. What you need to do is test to see if the field is blank.I usually do the following test:[code]<?phpif (strlen(trim(stripslashes($_POST['somefield']))) == 0) {//// field is blank //}?>[/code]Also, you can use:[code]<? $problem_statement .= 'New message'; ?>[/code]instead of[code]<? $problem_statement = $problem_statement . 'New Message'; ?>[/code]Another potential problem is that I don't see you initializing the $problem variable to '0'. I would initialize it to 'false' and then when you find an error set it to 'true', then your if statement would be:[code]<? if ($problem) ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/13707-running-if-else-argument-problems/#findComment-53276 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.