Question about 'isset'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Question about 'isset'

Post by Wldrumstcs »

I am working on a little project and understand that my problem could potentially be solved using 'isset'. However, I do not know how to use it properly, so I would greatly appreciate if someone could tell me what to write instead.

Okay, I am getting an error saying 'undefined index on line 7'. How can I rewrite this to work? I appreciate the help!

Code: Select all

<? IF($_SERVER['QUERY_STRING'] != "" AND $_SERVER['QUERY_STRING'] != "view=advanced") {
$body = "
<h3>There was an error in loading this page because a link was not clicked to access it.</h3>
<br>
<h5><a href='search.php'>Click here to access the search page</a>.</h5>
";
}ELSEIF($_GET["view"] == "" OR $_SERVER['QUERY_STRING'] = ""){
$advancedsearch_link = "
<p><a href='search.php?view=advanced'>Advanced Search</a></p>
";
$body = "
<form method='GET' action='results.php'>
	<input type='text' tabindex='1' name='query' size='25' maxlength='50'  onfocus=\"if(this.value == this.defaultValue){this.value = ''}\" value='Enter keywords here' />
	<input type='submit' value='Search' name='search_submit' tabindex='2'>
		$advancedsearch_link
		</form>
";
}
User avatar
harrison
Forum Commoner
Posts: 30
Joined: Thu Jun 09, 2005 12:23 am

Post by harrison »

check if a variable was passed to the script by this.

Code: Select all

if(isset($_GET['name'])){
$view = $_GET['name'];
}else{
echo "warning: name was not passed";
}
// or ...
$view = (isset($_GET['name'])?$_GET['name']:'');
Learn more of isset at google search.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

Thank you very much!
Post Reply