1

I have been designing a few websites. i have been trying to use multiple if(isset($_GET['type']) == 'page') { } and so forth functions. they seem not be be working can someone enlighten me?

<?php if(isset($_GET['type']) == 'all') { // View All Pages Title echo '<h3>View All Pages</h3>'; if($control1 == 'all') { echo '<table width="100%" border="0">'; echo '<tr>'; echo '<th scope="col">Page Name</th>'; echo '<th scope="col">Time Created</th>'; echo '<th scope="col">View</th>'; echo '<th scope="col">Edit</th>'; echo '<th scope="col">Delete</th>'; echo '</tr>'; $qry=mysql_query("SELECT * FROM page", $con); if(!$qry) { die("Query Failed: ". mysql_error()); } while($row=mysql_fetch_array($qry)) { echo '<tr>'; echo '<td height="38">'.$row['page_title'].'</td>'; echo '<td>'.$row['page_updated'].'</td>'; echo '<td><a href="page.php?view=page&page='.$row['page_link'].'">View</a></td>'; echo '<td><a href="page.php?edit='.$row['page_link'].'">Edit</td>'; echo '<td><a href="page.php?delete='.$row['id'].'">Delete</td>'; echo '</tr>'; } echo '</table>'; } else { echo "<p>You can't view all the pages. Your Account does not hold the correct priorirty</p>"; } } elseif(isset($_GET['type']) == 'add') { // Add New Page Title echo '<h3>Add New Page</h3>'; if($control1 == 'all') { echo '<p><a href="pages.php?type=add&add=control" target="new">Click Here to add a new page</a></p>'; } else { echo "<p>You can't add new pages. Your Account does not hold the correct priority.</p>"; } } elseif(isset($_GET['type']) == 'edit') { // Edit Pages Title echo '<h3>Edit a Page</h3>'; if($control1 == 'all') { echo '<table width="100%" border="0">'; echo '<tr>'; echo '<th scope="col">Page Name</th>'; echo '<th scope="col">Edit</th>'; echo '</tr>'; $qry=mysql_query("SELECT * FROM page", $con); if(!$qry) { die("Query Failed: ". mysql_error()); } while($row=mysql_fetch_array($qry)) { echo '<tr>'; echo '<td height="38">'.$row['page_title'].'</td>'; echo '<td><a href="page.php?edit='.$row['page_link'].'">Edit</td>'; echo '</tr>'; } echo '</table>'; } else { echo "<p>You can't edit any pages. Your Account does not hold the correct priority </p>"; } } ?> 

This is the exact code. If you can explain what it is I can do to fix it, it would be greatly appreciated! Thanks in advance!

5 Answers 5

2

isset($_GET['type']) returns a boolean value, so if you compare that boolean with anything that is not the same boolean ( isset($_GET['type']) == 'all' ) it will return false.

You should do

if ( isset($_GET['type']) && $_GET['type'] == 'all' ) { // code } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I never realized. So i should do this with all my $_GET functions?
0

Must be like this

if(isset($_GET['type']) && $_GET['type'] == 'page') 

Comments

0

isset return boolean: true or false. Therefore your code:

if(isset($_GET['type']) == 'page') 

won't work. You can change it like this:

if(isset($_GET['type']) and $_GET['type'] == 'page') 

Comments

0

The problem is that isset() function returns only TRUE or FALSE and you are comparing it to string. Just use it that way:

if (isset($_GET['type']) { if ($_GET['type'] == 'page') { //... } elseif($_GET['type'] == 'add') { //and so on... } } 

It's better to put isset test at the beginning so you won't check it in every if statement.

3 Comments

Everyone else said todo this: if(isset($_GET['type']) and $_GET['type'] == 'page') So I'm not sure if your answer is right?
Yes, it is right:) It makes no sense to check $_GET['type'] == 'add' if $_GET['type'] is not set. But if you will check it in every if statement, you will repeat yourself, but you really don't need to, you can check if $_GET is set only once. Try it and it will work for sure.
thanks Peter, i did and it kinda worked, i might not have implemented it correctly.
0

As I see it, isset() is returning a boolean (true/false) which you are comparing with "all", "add" and so on. That is not what you want.

you could do:

if (isset($_GET['type']) && $_GET['type'] == "all") { #your code here } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.