View Single Post
Old 01-18-2011, 02:52 PM   PM User | #1
sotrek
New to the CF scene

 
Join Date: Jan 2011
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
sotrek is an unknown quantity at this point
Exclamation $_GET not working

Hi guys,

i have a bit of a tedious problem.

i have the following code which performs an update.
Code:
                       $id = mysql_prep($_GET['subj']);
			
			$menu_name = mysql_prep($_POST['menu_name']);
			$position = mysql_prep($_POST['position']);
			$visible = mysql_prep($_POST['visible']);
			$query = "UPDATE subjects SET menu_name = '$menu_name', position = '$position', visible = '$visible' WHERE id = '$id'";
			$result = mysql_query($query, $connection);
			print_r($_REQUEST);
At the point where i am trying to GET the subj from my url : http://blablabal.edit_subject.php?subj=1
the GET returns no value. it should return 1 in this case..instead its empty.

anyone would know why?
The output i get from print_r
print_r($_REQUEST);
is: Array ( [subj] => [menu_name] => Produktion [position] => 2 [visible] => 1 [submit] => Edit Subject )

I have attached a bigger part of the code below for your consideration
Thanks!

Code:
if (isset($_POST['submit'])) {
		$errors = array();
	
		//Form Validation
		$required_fields = array('menu_name', 'position', 'visible');
		foreach($required_fields as $fieldname) {
			if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) {
				$errors[] = $fieldname;
			}
		}
	
		$fields_with_lengths = array('menu_name' => 30);
		foreach($fields_with_lengths as $fieldname => $maxlength) {
			if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) {
				$errors[] = $fieldname; 
			}
		}
	
		
		if (empty($errors)) {
			//Perform Update
			$id = mysql_prep($_GET['subj']);
			
			$menu_name = mysql_prep($_POST['menu_name']);
			$position = mysql_prep($_POST['position']);
			$visible = mysql_prep($_POST['visible']);
			$query = "UPDATE subjects SET menu_name = '$menu_name', position = '$position', visible = '$visible' WHERE id = '$id'";
			$result = mysql_query($query, $connection);
			print_r($_REQUEST);
			
			if (mysql_affected_rows() == 1) {
				//Sucess
				
			} else {
				//Failed
				
				$message = "The subject update failed." . mysql_error();
				
			}	
		} else {
			//Errors occured
			
		}
		
		} //end of: if (isset($_POST['submit']))

Last edited by sotrek; 01-18-2011 at 05:12 PM..
sotrek is offline   Reply With Quote