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']))
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Is there a form element named "subj", so that $_POST['subj'] would be being used as $_REQUEST['subj']? Try print_r on $_GET rather than $_REQUEST and see what values you have.
_REQUEST is a problem since its GET, POST and COOKIE by default all merged together in that order. If a POST or COOKIE is provided it will be included.
Post your HTML form.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
I am just using $_GET and $_POST
$_POST works..$_GET doesn't
basically i need to retrieve the value of 1 from 'subj' on my link: http://blabla/edit_subject.php?subj=1
in some way so i can add it to my UPDATE statement.
$_GET has worked in the past on other parts of the website i m building without a problem..
I didn't ask you whether you are using request, I asked you to post your html form.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
That will be it. Your GET request is in a branch of your POST. The only way it'll be set is its passed on your form action. Its a set variable, but without the echo its empty.
Alternatively you can pass it through a hidden input and retrieve from post.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php