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']))