Alternative to register_globals using _POST

I am new to php and my client is wanting me to make some changes to their code. The problem is that register_globals is on and when the site was moved to a new host register_globals was set to off and cannot be turned on.

Therefore I have to use the $_POST[] to get the form data out. below is the code to check if the form is mandatory

So how do i do this using _POST?

[php]
$form_fields[‘property’][]= array(name=>“page”,label=>“page”,default_val=>"",required=>“y”);
$form_fields[‘property’][]= array(name=>“type”,label=>“type”,default_val=>"",required=>“y”);

$return=commit_data(“properties”, $form_fields[‘property’],$form_update_id,$tidy=‘y’,$session=’’);

FUNCTION commit_data($table, $form_fields,$update_id,$tidy=‘y’,$session=’’)
{
global $err_list;
$err=input_check($form_fields);
if($err==1){return $err_list;}
$field_count=count($form_fields);
$i=1;
foreach($form_fields AS $field)
{
$name=form_name_conv($field[name]);
global ${$name};
if($session==1){$SESSION['sess’.$field[name]]=${$name}; continue;}
${$name}=mysql_escape_string(${$name});
if($field[commit]<>“n” && (${$name}<>$field[default_val] || ${$name}==""))
{
$sql_columns.="$field[name]";
$sql_fields.="’".${$name}."’";
$sql_update.="$field[name]=’".${$name}."’";
$sql_columns.=",";
$sql_fields.=",";
$sql_update.=",";
}

			$i++;
		}
	if($session==1){return;}
	//GET RID OF LAST ,
	$sql_columns=substr_replace($sql_columns,"",-1);
	$sql_fields=substr_replace($sql_fields,"",-1);
	$sql_update=substr_replace($sql_update,"",-1);

	if($update_id=="")
		{
			$sql="INSERT INTO $table ($sql_columns) VALUES ($sql_fields)";
		}else{
			$sql="UPDATE $table SET $sql_update WHERE id='$update_id'";
		}
	if(!($return=mysql_query($sql)))
		{
			$mysql_err=mysql_error();
			echo("DB ERROR: $mysql_err");
		}
	if($update_id=="")
		{		
			$return_id=mysql_insert_id();
		}else{
			$return_id=$update_id;
		}
	//echo($sql);
	if($tidy=="y")
		{
			reset($form_fields);
			foreach($form_fields AS $field)
				{
					//no need to redeclare global
					${form_name_conv($field[name])}="";
				}
				
		}
	return $return_id;
}

FUNCTION input_check($form_fields)
{
global $err_list;
foreach($form_fields AS $item)
{
if($item[‘required’]==“y”)
{
$name=form_name_conv($item[name]);
global ${$name};
$default=$item[‘default_val’];
$label=$item[‘label’];
if(${$name}==$default || ${$name}=="")
{
$err_name=“err_”.$name;
global ${$err_name};
${$err_name}=$label.“is a required field”;
$err_list.="

  • ".$label." is required
  • ";
    $err=1;
    }
    }
    }
    return $err;
    }[/php]

    Thanks

    Stu

    Let your form code is below [code]

    [/code]

    You can get the Name in result.php using POST like below :
    [php]

    <?php $name = $_POST['txtname']; //You can get the name using POST like this print $name; ?>[/php]
    Sponsor our Newsletter | Privacy Policy | Terms of Service