Jump to content

[SOLVED] IF URL Variable Exists?


kyleldi

Recommended Posts

http://yourserver.com/index.php?var=123

<?php
  if($_GET['var']){
    echo $_GET['var'];
    //Put script here
  }
?>

Better to use isset when checking for user defined variables ($_POST, $_GET, $_COOKIE etc). This will prevent Notice messages from appearing if the variable doesn't exist.

<?php
  if(isset($_GET['var'])){
    echo $_GET['var'];
    //Put script here
  }
?>

Ok, I put that in my code but i'm getting an "unexpected $end" error.  Any ideas?  What it's supposed to do is output the url variable if there is one, otherwise it shows one thing if there are items in the db that are active, or another thing if there are no active items.

 

<?php
  if(isset($_GET['positionid'])){
    echo $_GET['positionid'];
    echo '<div class="jobdetail">
  <p><span class="style8">Position:</span>'.ucwords($row_rs_positiondetail['title']).'<br />
    <span class="style8">Date Added:</span>'.ucwords($row_rs_positiondetail['date']).'<br />
    <span class="style8">Pay:</span>'.ucwords($row_rs_positiondetail['pay']).'</p>
  <p class="style8">Summary: <span class="jobdetail">'.ucwords($row_rs_positiondetail['summary']).'</span></p>
  <p class="style8">Duties & Responsibilities: <span class="jobdetail">'.ucwords($row_rs_positiondetail['duties_responsibilities']).'</span></p>
  <p class="style8">Qualification Requirements: <span class="jobdetail">'.ucwords($row_rs_positiondetail['qualification_requirements']).'</span></p>
  <p class="style8">Education/Experience: <span class="jobdetail">'.ucwords($row_rs_positiondetail['education_experience']).'</span></p>
  <p class="style8">Language Skills: <span class="jobdetail">'.ucwords($row_rs_positiondetail['langauge_skills']).'</span></p>
  <p class="style8">Mathmatical Skills: <span class="jobdetail">'.ucwords($row_rs_positiondetail['mathmatical_skills']).'</span></p>
  <p class="style8">Reasoning Ability: <span class="jobdetail">'.ucwords($row_rs_positiondetail['reasoning_ability']).'</span></p>
  <p class="style8">Physical Demands: <span class="jobdetail">'.ucwords($row_rs_positiondetail['physical_demands']).'</span></p>
  <p class="style8">Work Enviornment: <span class="jobdetail">'.ucwords($row_rs_positiondetail['work_enviornment']).'</span></p>
  <div class="apply">
    <p align="center" class="style8"><a href="apply.php?positionid='.ucwords($row_rs_positiondetail['positionid']).'">Apply For This Position</a></p>
  </div>
</div>';
}
else{
if ($row_rs_positions['active'] == 'Yes') {
   do { 
      echo '<div class="displayjobs">
            <div class="jobheading">
               <p><a href="careers.php?positionid='.ucwords($row_rs_positions['positionid']).'">'.ucwords($row_rs_positions['title']).'</a><strong> - 
               <span class="style5">Added: '.ucwords($row_rs_positions['date']).'</span></strong></p>
            </div>
            <div class="jobdesc">
            <p>'.substr($row_rs_positions['summary'], 0,150).'... <a href="careers.php?positionid='.ucwords($row_rs_positions['positionid']).'">View Position</a></p>
            </div>
         </div>';
    } 
    while($row_rs_positions = mysql_fetch_assoc($rs_positions));
}
else{
   echo '<div class="jobopenings"><p align="center">Thank you for your interest. Currently we do not have any job openings within The Company. We are, however, always accepting resumes and applications. If you would like to be considered for a future position here, please submit a resume or application <a href="submitapp.php">here</a>.</p><p align="center"><span class="pdfdownload">Download a copy of our <img src="images/pdf-icon.jpg" alt="Adobe PDF" width="16" height="15" /> <a href="downloads/pdf/employment_application.pdf">Employment Application</a> (PDF, 3690K)</span></p></div>';
}
?>

You have a missing closing brace. Add one before your closing php tag.

 

To see where your code blocks start/end you should indent you code.

if(isset($_GET['positionid']))
{
    echo $_GET['positionid'];
    echo '<div class="jobdetail">
  <p><span class="style8">Position:</span>'.ucwords($row_rs_positiondetail['title']).'<br />
    <span class="style8">Date Added:</span>'.ucwords($row_rs_positiondetail['date']).'<br />
    <span class="style8">Pay:</span>'.ucwords($row_rs_positiondetail['pay']).'</p>
  <p class="style8">Summary: <span class="jobdetail">'.ucwords($row_rs_positiondetail['summary']).'</span></p>
  <p class="style8">Duties & Responsibilities: <span class="jobdetail">'.ucwords($row_rs_positiondetail['duties_responsibilities']).'</span></p>
  <p class="style8">Qualification Requirements: <span class="jobdetail">'.ucwords($row_rs_positiondetail['qualification_requirements']).'</span></p>
  <p class="style8">Education/Experience: <span class="jobdetail">'.ucwords($row_rs_positiondetail['education_experience']).'</span></p>
  <p class="style8">Language Skills: <span class="jobdetail">'.ucwords($row_rs_positiondetail['langauge_skills']).'</span></p>
  <p class="style8">Mathmatical Skills: <span class="jobdetail">'.ucwords($row_rs_positiondetail['mathmatical_skills']).'</span></p>
  <p class="style8">Reasoning Ability: <span class="jobdetail">'.ucwords($row_rs_positiondetail['reasoning_ability']).'</span></p>
  <p class="style8">Physical Demands: <span class="jobdetail">'.ucwords($row_rs_positiondetail['physical_demands']).'</span></p>
  <p class="style8">Work Enviornment: <span class="jobdetail">'.ucwords($row_rs_positiondetail['work_enviornment']).'</span></p>
  <div class="apply">
    <p align="center" class="style8"><a href="apply.php?positionid='.ucwords($row_rs_positiondetail['positionid']).'">Apply For This Position</a></p>
  </div>
</div>';
}
else
{
    if ($row_rs_positions['active'] == 'Yes')
    {
       while($row_rs_positions = mysql_fetch_assoc($rs_positions))
       {
          echo '<div class="displayjobs">
                <div class="jobheading">
                   <p><a href="careers.php?positionid='.ucwords($row_rs_positions['positionid']).'">'.ucwords($row_rs_positions['title']).'</a><strong> -
                   <span class="style5">Added: '.ucwords($row_rs_positions['date']).'</span></strong></p>
                </div>
                <div class="jobdesc">
                <p>'.substr($row_rs_positions['summary'], 0,150).'... <a href="careers.php?positionid='.ucwords($row_rs_positions['positionid']).'">View Position</a></p>
                </div>
             </div>';
        }
    }
    else
    {
       echo '<div class="jobopenings"><p align="center">Thank you for your interest. Currently we do not have any job openings within The Company. We are, however, always accepting resumes and applications. If you would like to be considered for a future position here, please submit a resume or application <a href="submitapp.php">here</a>.</p><p align="center"><span class="pdfdownload">Download a copy of our <img src="images/pdf-icon.jpg" alt="Adobe PDF" width="16" height="15" /> <a href="downloads/pdf/employment_application.pdf">Employment Application</a> (PDF, 3690K)</span></p></div>';
    }
}

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.