2012-04-12 36 views
1

請幫我關於在標題中指明的問題。爲什麼這個通知(12次):未初始化字符串偏移量:0 app_vsf.php上線90

的代碼部分是:

<?php 
// framework related things in this file. 

// vsf = Very Simple Framework 

$vsf = new stdClass; 

// default app_layout file 
$vsf->app_layout = 'app_layout.php'; 

// define the 'index' file, where we should link back to. 
// Need to include the path, otherwise S.E. friendly URLS get messed up. 
$vsf->self = '/mapcal/index.php'; 

// to support search engine friendly URLS, grab data from PATH_INFO 
if (isset($_SERVER["PATH_INFO"])) { 
$tmp_array = explode("/",$_SERVER["PATH_INFO"]); 

for ($index = 0; $index < count($tmp_array); $index++) { 
// only want the odd elements, they are the parameters. The even ones are the values 
if ($index % 2 == 0) { continue; } 
$_REQUEST[$tmp_array[$index]] = $tmp_array[$index+1]; 
} 
} 

// these functions are for form error handling 
$errorfields = array(); 

$errormsgs = array(); 

$errorwasthrown = FALSE; 

function adderrmsg($field = '', $msg = '') { 
global $errorfields; 
global $errormsgs; 
global $errorwasthrown; 

if ($field) { 
$errorfields[] = $field; 
} 
if ($msg) { 
$errormsgs[] = $msg; 
} 
$errorwasthrown = TRUE; 
} 

function displayformerrors($errhdr = 'The following errors occured:') { 
global $errorfields; 
global $errormsgs; 

if (empty($errorfields) and empty($errormsgs)) {return;} 

if (! empty($errormsgs)) { 
print "<p style='color: red;'>$errhdr<br>\n"; 

foreach ($errormsgs as $msg) { 
    print "&#8226; $msg<br>\n"; 
    } 
print "</p>\n\n"; 
} 
} 

function displayformlabel ($field = '', $label = '') { 
global $errorfields; 
if (in_array($field,$errorfields)) { 
print "<span style='color: red;'>$label</span>"; 
} 
else { 
print $label; 
} 
} 

function reuseform($formaction = 'new',$field_list = '',$query = '') { 
if ($formaction == "new") { 
foreach (split(",",$field_list) as $field) { 
    global ${$field}; 
    ${$field} = ''; 
    } 
} 
elseif ($formaction == 'form') { 
foreach (split(",",$field_list) as $field) { 
    global ${$field}; 
    ${$field} = $_REQUEST[$field]; 
    } 
} 

elseif ($formaction == 'query') { 
foreach (split(",",$field_list) as $field) { 
    global ${$field}; 
    ${$field} = $query[$field]; 
    } 
} 

} // close function reuseform 

?> 

線無90是:$ {$字段} = $查詢[$字段];

通知正在顯示12倍,因爲有在形式12個字段,但爲什麼這是顯示,我無法看到在表單字段中的數據進行編輯的目的。 請幫我解決這個問題。

+0

我從來沒有見過'$ {$ VAR_NAME}'曾經在我短暫的編程生涯的用法。 – hjpotter92 2012-04-12 21:15:27

+1

變量變量... – 2012-04-12 21:16:18

+1

似乎我們錯過了調用reuseform的地方。 – 2012-04-12 21:21:17

回答

0

檢查以確保$ _REQUEST持有變量。

此外,reuseform似乎默認設置$查詢爲''而不是Array()...是$查詢是否正確設置?這個錯誤表明它不是。

0

顯然${$field}評估爲"0"$query["0"]未定義。

0

你可以使用這個快速修復與isset

if(isset($GLOBALS[${$field}])) 
{ 
    ${$field} = $query [$field]; 
} 
+0

非常感謝你爸爸......通知問題已經消失,但字段值沒有顯示,而是像以前一樣保持空白。你會給我一個解決方案嗎? – rock 2012-04-12 21:36:49

+0

把你在哪裏調用'reuseform'表單中的腳本..然後..我不會對你如何能最好的解決這個 – Baba 2012-04-12 21:38:08

+0

我要編輯自己的帖子爲把劇本 – rock 2012-04-12 21:57:42

相關問題