//get var of posted info so user does not
//have to reinsert if if validation = false
if(!isset($_POST['FactionChanges'])){ $faction_name = ''; }
else { $faction_name = "".$_POST['factionname'].""; }
//without form submit, num_errors = 0
if(!isset($_POST['FactionChanges'])){ $num_errors = 0; }
//without form submit, success = 0
if(!isset($_POST['FactionChanges'])){ $success = 0; }
//error handling section [upon form submit]
if(isset($_POST['FactionChanges'])){
//deal with individual form section posts
//-->Faction Name
if(isset($_POST['factionname'])){
//set var for error
//array to use here
$errors = array();
$unsani_faction_name = $_POST['factionname'];
$new_faction_name = str_replace(",", "", $unsani_faction_name);
$faction_name = mysql_real_escape_string($new_faction_name);
$faction_name = preg_replace('/\s\s+/', ' ', $faction_name);
$faction_name = stripslashes($faction_name);//strips slashes from name
//remove special chars except: "& $ £^- ()"
$faction_name = preg_replace('/[^a-z0-9\s£&$\^\(\)-]/i', '', $faction_name);
$string_length = strlen($faction_name);
if($string_length < 3 || $string_length > 20){
$errors[] = 'Name: [between 3-20 characters]'; }
else{
$sql = mysql_query("SELECT * FROM ".TBL_TBL_FACTIONS."
WHERE f_name='$faction_name'");
$num_rows = mysql_num_rows($sql);
if ($num_rows > 0){ $errors[] = 'Name: [same faction name in existance]'; }
else { mysql_query("UPDATE ".TBL_FACTIONS." SET f_name='$faction_name'
WHERE f_id=$userfaction_id");
header("Location: ".$page_name."?section=actions");
//$success = 1; [DOES NOT work here]
}
}//else
}//if post factionname
$num_errors = count($errors);
if($num_errors === NULL){ $success = 1; }
}
//$success = 1; [works here]
if($num_errors > 0){ echo '<p class="error"><strong>Error:</strong>
The form could not be submitted because there are errors present</p>'; }
//add something here to only display sucess only if form is success
if($success == 1){ echo '<p class="success"><strong>Success:</strong>
Your faction changes have been made</p>'; }
當提交成功的表單輸入時,無法顯示成功框? 我自己做了一些調試,並且插入了我嘗試插入成功變量的位置。我真的很難過這個。提交表單提交後,php變量未設置爲期望值
謝謝。 如果我想添加更多的表單更新,我將不得不改變每個人的整體成功的價值? – 2010-08-18 23:48:32
如何阻止用戶輸入:faction.php?section = actions&success = 1並顯示綠色成功框? – 2010-08-18 23:49:10
@Callum Johnson,不知道我理解你的第一條評論,但至於你的第二條評論:你不是,真的。你可以用會話做一些魔術或檢查引用者(這是不可信的)。 – jasonbar 2010-08-18 23:54:08