在提交表单时遇到未定义的变量问题。请帮助
有人可以告诉我我错过了什么吗?
我打算调用函数' process_input'对于表单提交和内部进程输入,我得到ip / uid / pwd详细信息。
$.ajax({
type : 'POST',
url : 'post_process.php',
data : {
func : 'process_input'
},
}).done(function(data) {
// show the response
$("#response").html(data);
PHP
if (isset ( $_POST ['func'] ) && ! empty ( $_POST ['func'] )) {
$func = trim ( $_POST ['func'] );
switch ($func) {
case 'process_input' :
process_input ();
break;
..........
}
}
function process_input() {
header ( 'Content-Type: text/html; charset=utf-8' );
if (isset ( $_POST ['ip'] ) && ! empty ( $_POST ['ip'] )) {
$ip = trim ( $_POST ["ip"] );
}
if (isset ( $_POST ['uid'] ) && ! empty ( $_POST ['uid'] )) {
$uid = trim ( $_POST ["uid"] );
}
if (isset ( $_POST ['pwd'] ) && ! empty ( $_POST ['pwd'] )) {
$pwd = trim ( $_POST ["pwd"] );
}
echo "$ip $uid $pwd <br>";
...
}
注意:未定义的变量:第41行的ip in
所有变量($ip
$uid
$pwd
)都是未定义的
答案 0 :(得分:0)
问题在于这一行;
echo "$ip $uid $pwd <br>";
使用检查上方的默认值定义变量。因为可能存在并非所有这些都被设置的情况。像这样;
function process_input() {
$ip = '';
$uid = '';
$pwd = '';
header ( 'Content-Type: text/html; charset=utf-8' );
....