kyleldi Posted March 10, 2009 Share Posted March 10, 2009 Is it possible to make an IF statement run from a url variable? What I want to do is write a small script that states IF a url variable exists, a script runs, while if it does not that script is skipped and the next script is ran. any ideas? Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/148810-solved-if-url-variable-exists/ Share on other sites More sharing options...
rhodesa Posted March 10, 2009 Share Posted March 10, 2009 http://yourserver.com/index.php?var=123 <?php if($_GET['var']){ echo $_GET['var']; //Put script here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148810-solved-if-url-variable-exists/#findComment-781433 Share on other sites More sharing options...
wildteen88 Posted March 10, 2009 Share Posted March 10, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148810-solved-if-url-variable-exists/#findComment-781445 Share on other sites More sharing options...
kyleldi Posted March 10, 2009 Author Share Posted March 10, 2009 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148810-solved-if-url-variable-exists/#findComment-781473 Share on other sites More sharing options...
br0ken Posted March 10, 2009 Share Posted March 10, 2009 You need to either add a } at the end of your code or change the 'else { if {' to 'else if {' Quote Link to comment https://forums.phpfreaks.com/topic/148810-solved-if-url-variable-exists/#findComment-781481 Share on other sites More sharing options...
wildteen88 Posted March 10, 2009 Share Posted March 10, 2009 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>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/148810-solved-if-url-variable-exists/#findComment-781484 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.