Jump to content

$_GET issues with what's being displayed...


geudrik

Recommended Posts

Alright, I'm sure I'm missing something here...  As soon as a url has ?page after the .php of the page, the $_GET variable 'page' HAS BEEN SET, right?  I mean, it's got no value, I understand that, but IT HAS been declared, yes?

Assuming that, the code below is what I am unable to get working...

This code is live here.  If you click 'Links' at the top of the page, you get a list of pages that exist.  However, the main page is ALWAYS displayed at the top (See for your self).

 

How do I change my code around so that only one of three things (with the exception of the admin login - I want that to show up right below the index content when the link is clicked as it does now) is displayed?

1) Main page is nothing or something unkown is set

2) Page content, with ID retrieved from ?pid=

3) List of pages

 

<?php 			

		include('includes/db.php');
		dbconnect();

		if(isset($_GET['pid']))
		{
			$id = $_GET['pid'];
			$sql = "SELECT body FROM cms WHERE id = '$id'";
			if( !@mysql_query($sql) )
			{
				echo("There was something wrong with the page you requested, so I'm giving up trying to regurgitate the gobble di gook");
			} else {
				$result = mysql_query($sql);
				echo($result);
			}

		}

		if( (!$_GET['pid']) || (!$_GET['pagelist']) )
		{
			$homesql = "SELECT body FROM cms WHERE title = 'SpaazZ Home'";
			$homeresult = mysql_query($homesql) or die(mysql_error());
			while( $row = mysql_fetch_assoc($homeresult) ) 
			{
				$content = $row['body'];
			}
			$homecontent = stripslashes(nl2br($content));
			echo($homecontent);

		}

		if( $_GET['pagelist'] )
		{
			$sql = "SELECT * FROM cms";
			$result = mysql_query($sql) or die(mysql_error());
			while( $row = mysql_fetch_assoc($result) ) 
			{

				$id        = $row['id'];
				$title     = $row['title'];

				echo("<a href='index.php?pid=$id'>$title</a><br />");
			}

		}

		mysql_close();

		if( isset($_GET['admin']) )
		{
			include('includes/templates/adminlogin.tpl');
		}



?>

 

And no, I'm not getting errors or anything, it's just now working...  ???

Link to comment
Share on other sites

@DarkWater "?page" will make it declared.

 

$_GET['pagelist'] is null and null evaluates to false so

if( $_GET['pagelist'] )

won't work.

if( isset($_GET['pagelist']) )

 

Will work.

 

Oh wow, I remember it didn't work at one point, but I guess now it does.  Cool.  Man, I need some coffee or something.  Brb. D:

Link to comment
Share on other sites

Nah, not working and now I wind up with resource error #4 - check it out live - www.spaazz.net

That resource error is only when I try to view a page using ?pid=  (use 3 or 4 - that all that exists in the database for now)

 

Current code (has isset() )

<?php 			

		include('includes/db.php');
		dbconnect();

		if(isset($_GET['pid']))
		{
			$id = $_GET['pid'];
			$sql = "SELECT body FROM cms WHERE id = '$id'";
			if( !@mysql_query($sql) )
			{
				echo("There was something wrong with the page you requested, so I'm giving up trying to regurgitate the gobble di gook");
			} else {
				$result = mysql_query($sql);
				echo($result);
			}

		}

		if( (!isset($_GET['pid'])) || (!isset($_GET['pagelist'])) )
		{
			$homesql = "SELECT body FROM cms WHERE title = 'SpaazZ Home'";
			$homeresult = mysql_query($homesql) or die(mysql_error());
			while( $row = mysql_fetch_assoc($homeresult) ) 
			{
				$content = $row['body'];
			}
			$homecontent = stripslashes(nl2br($content));
			echo($homecontent);

		}

		if( isset($_GET['pagelist']) )
		{
			$sql = "SELECT * FROM cms";
			$result = mysql_query($sql) or die(mysql_error());
			while( $row = mysql_fetch_assoc($result) ) 
			{

				$id        = $row['id'];
				$title     = $row['title'];

				echo("<a href='index.php?pid=$id'>$title</a><br />");
			}

		}

		mysql_close();

		if( isset($_GET['admin']) )
		{
			include('includes/templates/adminlogin.tpl');
		}



?>

Link to comment
Share on other sites

Good call chief.  Resource error gone, but it sill isn't working like it should.  I fixed that one block ...

 

<?php
		if(isset($_GET['pid']))
		{
			$id = $_GET['pid'];
			$sql = "SELECT * FROM cms WHERE id = '$id'";
			if( !mysql_query($sql) )
			{
				echo("There was something wrong with the page you requested, so I'm giving up trying to regurgitate the gobble di gook");
			} else {
				$result = mysql_query($sql);
				while( $row = mysql_fetch_assoc($result) );
				{
					echo($row['body']);
				}
			}

		}
?>

Link to comment
Share on other sites

<?php
		if(isset($_GET['pid']))
		{
			$id = $_GET['pid'];
			$sql = "SELECT * FROM cms WHERE id = '$id'";
			if( !($result = mysql_query($sql)) )
			{
				echo("There was something wrong with the page you requested, so I'm giving up trying to regurgitate the gobble di gook");
			} else {
				while( $row = mysql_fetch_assoc($result) );
				{
					print_r($row);
				}
			}

		}
?>

 

Fixed so it uses 1 query and show me the output, if any, of the script now.

Link to comment
Share on other sites

Oooh, sweet. Thanks.

 

if($_GET['pid'])
		{
			$id = $_GET['pid'];
			$sql = "SELECT * FROM cms WHERE id = '$id'";
			if( !($result = mysql_query($sql)) )
			{
				echo("There was something wrong with the page you requested, so I'm giving up trying to regurgitate the gobble di gook");
			} else {
				while( $row = mysql_fetch_assoc($result) );
				{
					print_r($row['body']);
				}
			}

		}

 

Now that's now working right.  I'm not getting anything displayed out...

Link to comment
Share on other sites

My current code looks like:

if(isset($_GET['pid']))
		{
			$id = $_GET['pid'];
			$sql = "SELECT body FROM cms WHERE id = '$id'";

			if( !($result = mysql_query($sql)) )
			{
				echo("There was something wrong with the page you requested, so I'm giving up trying to regurgitate the gobble di gook");
			} else {
				$result = mysql_query($sql);
				while( $row = mysql_fetch_assoc($result) );
				{
					$body = $row['body'];
					$display = stripslashes(nl2br($body));
					echo($display);
					echo($sql);
				}
			}

		}

 

With that code in the page, check it out here: http://www.spaazz.net/index.php?pid=4

I've run the query in phpmyadmin and it DOES work, so I know data is being retrieved.

 

Can someone help me trouble shoot this?  I can't seem to figure out why this won't work....

Link to comment
Share on other sites

I'd advise updating your code to

if(isset($_GET['pid']))
		{
			$id = mysql_real_escape_string($_GET['pid']);
			$sql = "SELECT body FROM cms WHERE id = '$id'";

			if( !($result = mysql_query($sql)) )
			{
				echo("There was something wrong with the page you requested, so I'm giving up trying to regurgitate the gobble di gook");
			} else {
				$result = mysql_query($sql);
				while( $row = mysql_fetch_assoc($result) );
				{
					$body = $row['body'];
					$display = stripslashes(nl2br($body));
					echo($display);
					echo($sql);
				}
			}

		}

 

or removing that link... your choice.

 

As for the main question of why it isn't working... var_dump() your variables as you go. When it dumps a variable with a value you don't expect it to be, figure out why it isn't what you expect.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.