Function to escape POST data and store it dynamically
Posted: Thu Jan 19, 2006 5:32 am
Hi guys,
I thought of defining a function to save rewriting the same piece of code loads of times, althought it's not totally necessary I want to fix it.
Here is my code:
I know I probably need to look into variable variables but I don't really understand them or how to implement them.
I've tried doing it like this also:
But I get the same errors, which with E_ALL on, look like this:
Thanks for any help 
I thought of defining a function to save rewriting the same piece of code loads of times, althought it's not totally necessary I want to fix it.
Here is my code:
Code: Select all
//Define a validation method to save re-typing
function validate_input($field, $msgvar = 'msg', $method = '_POST') {
if($$method[$field]) {
$$field = mysql_real_escape_string(trim(stripslashes($$method[$field])));
return TRUE;
} else {
$$field = FALSE;
$$msgvar .= '<font color="red">You haven\'t entered a ' . $field . '.</font><br />';
return FALSE;
}
}I've tried doing it like this also:
Code: Select all
//Define a validation method to save re-typing
function validate_input($field, $msgvar = 'msg', $method = 'POST') {
if($_{$method}[$field]) {
${$field} = mysql_real_escape_string(trim(stripslashes($_{$method}[$field])));
return TRUE;
} else {
${$field} = FALSE;
${$msgvar} .= '<font color="red">You haven\'t entered a ' . $field . '.</font><br />';
return FALSE;
}
}Code: Select all
PHP Notice: Undefined variable: _ in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 10 PHP Notice: Undefined variable: msg in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 15 PHP Notice: Undefined variable: _ in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 10 PHP Notice: Undefined variable: msg in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 15 PHP Notice: Undefined variable: _ in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 10 PHP Notice: Undefined variable: msg in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 15 PHP Notice: Undefined index: img in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\addcar.php on line 23 PHP Notice: Undefined variable: msg in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\addcar.php on line 27 PHP Notice: Undefined variable: _ in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 10 PHP Notice: Undefined variable: msg in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\functions.php on line 15 PHP Notice: Undefined index: img in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\addcar.php on line 143 PHP Notice: Undefined index: priv_sale in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\addcar.php on line 155 PHP Notice: Undefined index: priv_sale in D:\Webspace\wrightandshields.co.uk\wwwroot\collegestuff\carmanage\addcar.php on line 157