Jump to content

Help me understand why one item takes precedence over the other.


Darkmatter5

Recommended Posts

If the URL to the page is http://www.hi.com/editjob.php?job_id=1 and there's a drop down list on the page named 'job' with a submit button named 'load'

.

When this code is run

<?php
if(!isset($_POST['load']) && !isset($_GET['job_id'])) {
  $byrndb->job_list(2,$job);
} elseif(isset($_POST['load'])) {
  $job=$_POST['job'];
  $byrndb->job_list(2,$job);
} elseif(isset($_GET['job_id'])) {
  $job=$_GET['job_id'];
  $byrndb->job_list(2,$job);
}
?>

why does the $_GET['job_id'] seem to take precedence over $_POST['job']? If $_POST['job'] is checked before $_GET['job_id'], shouldn't $job be set to $_POST['job']'s value over $_GET['job_id'].

<?php
// create an .htaccess file that reads the line:
// php_flag register_globals off

if(!isset($_POST['load']) && !isset($_GET['job_id'])) {
  $byrndb->job_list(2,$job); // NOTICE: $job is undefined here
} elseif(isset($_POST['load'])) {
  $job=$_POST['job'];
  $byrndb->job_list(2,$job);
} elseif(isset($_GET['job_id'])) {
  $job=$_GET['job_id'];
  $byrndb->job_list(2,$job);
}
?>

$job isn't defined yet, so if a specific job isn't defined in job_id or by what is passed by the load button, then it's null and a generic list is generated with no specific job selected. Otherwise I'm wanting for what's selected in the dropdown to be most important, if something is in the dropdown AND in the URL as job_id then use the dropdown list selection over the URL variable.

 

Here's the form code.

 

<form method="post">
<input name='load' type='submit' value='Load record' />
</form

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.