geudrik Posted August 13, 2008 Share Posted August 13, 2008 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... ??? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 It's not declared until there is a value for it. ?page will not make it declared as $_GET['page'], you'll need to just parse the query string. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 13, 2008 Share Posted August 13, 2008 @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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 @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: Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 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'); } ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 echo($result); You can't echo the results of a query like that because all that mysql_query() returns is a resource to the result set. Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 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']); } } } ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Why do you run the query twice? Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 Mostly because i was up until 4 last night finishing the admin panel :-\ I'll fix that once I get the site working as it should... Any thoughts on why it isnt doing what *i THINK* the code says? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 <?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. Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 http://www.spaazz.net/index.php?pid=4 That's the url right there. That's the only input. Its all links. http://www.spaazz.net/index.php?pagelist If you go there, you see the two pages in the table. That's working correctly minus the main page showing above it. Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 Anyone have any thoughts? Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 Just to make sure Im not over looking something... if( (!isset($_GET['pid'])) || (!isset($_GET['pagelist'])) ) That DOES mean if pid OR pagelist arent set, display, correct? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 13, 2008 Share Posted August 13, 2008 Just to make sure Im not over looking something... if( (!isset($_GET['pid'])) || (!isset($_GET['pagelist'])) ) That DOES mean if pid OR pagelist arent set, display, correct? yes Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 Then why, when one or the other is set, is the index being displayed? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 13, 2008 Share Posted August 13, 2008 because one or the other is NOT set... use && of if you want to make sure both aren't set. Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 I think then I might be confused. IF 1 OR 2 IS NOT SET - display index page. if 1 set - display 1 if 2 set - display 2 Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 13, 2008 Share Posted August 13, 2008 With ||: if 1 set, 2 set: don't display if 1 set, 2 not set: display if 1 not set, 2 set: display if 1 not set, 2 not set: display With &&: if 1 set, 2 set: don't display if 1 set, 2 not set: don't display if 1 not set, 2 set: don't display if 1 not set, 2 not set: display choose the one you want. Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 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... Quote Link to comment Share on other sites More sharing options...
geudrik Posted August 13, 2008 Author Share Posted August 13, 2008 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.... Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 13, 2008 Share Posted August 13, 2008 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. Quote Link to comment 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.