strategos Posted January 22, 2012 Share Posted January 22, 2012 Hello, this is my first PHP project, and I am having issues getting it to correctly display an error ONLY if the input is an error It displays the error upon first load of the page w/o pressing submit. How would I use isset($_POST['submit']) to fix it? <?php $inputid = $_POST['steamid']; $steam_prefix = substr($inputid, 0, 10); $prefix_length = 10; $char_total = strlen($inputid); $steam_suffixchars = ($char_total - $prefix_length); $suffix_check = substr($inputid, 10, $steam_suffixchars); $class_set = "notranslate"; $is_submit = isset($_POST['submit']); if(is_numeric($suffix_check) == true) $suffix_valid = true; elseif(is_int($suffix_check) == false) $suffix_valid = false; if($char_total > 25 || $char_total < 11) $char_valid = false; else $char_valid = true; if($steam_prefix === "STEAM_0:1:" || $steam_prefix === "STEAM_0:0:") $prefix_check = true; elseif($steam_prefix != "STEAM_0:1:" || $steam_prefix != "STEAM_0:0:") $prefix_check = false; if (preg_match('/^[A-Z0-9-:]+$/', $inputid)) $chars_matched = true; else $chars_matched = false; if($suffix_check == true && $prefix_check == true && $char_valid == true && $chars_matched == true) echo "Approved!"; elseif(isset($_POST['anon'])) echo "Approved!"; else echo "error!"; ?> Link to comment https://forums.phpfreaks.com/topic/255502-conditional-display-issue/ Share on other sites More sharing options...
trq Posted January 22, 2012 Share Posted January 22, 2012 Wrap all your current code within: if (isset($_POST['submit'])) { // your code here } You should always do this when dealing with $_POST & $_GET arrays anyway. Link to comment https://forums.phpfreaks.com/topic/255502-conditional-display-issue/#findComment-1309986 Share on other sites More sharing options...
strategos Posted January 22, 2012 Author Share Posted January 22, 2012 Ok thank you very much. When I tried that, i was missing the {} lol Link to comment https://forums.phpfreaks.com/topic/255502-conditional-display-issue/#findComment-1309989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.